File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
3+ import re
4+
5+
6+ def group_match (num = None ):
7+ if num is None :
8+ print ("The function `group_match` takes a number." )
9+ else :
10+ # group_num_re = re.compile("(\d\d\d)-(\d\d\d)-(\d\d\d\d)")
11+ group_num_re = re .compile ("(\(\d\d\))-((\d\d\d)-(\d\d\d)-(\d\d\d))" )
12+ num_search = group_num_re .search (num )
13+
14+ try :
15+ if num_search .group ():
16+ print ("\n -Your number {} matches the pattern." .format (
17+ num_search .group ()))
18+ num_groups = len (num_search .groups ())
19+ print (
20+ " * Number of groups/sections in the number: {}" .format (num_groups ))
21+ print (" * Groups: " )
22+ # print(num_search.groups())
23+ # print(num_search.groups()[2:])
24+ print (" 1. {}" .format (
25+ num_search .groups ()[0 ].rstrip (")" ).lstrip ("(" )))
26+ for i in range (len (num_search .groups ()[2 :])):
27+ print (" {}. {}" .format (
28+ i + 2 , num_search .groups ()[2 :][i ]))
29+
30+ except AttributeError :
31+ print ("\n -Your number {} does not match the pattern." .format (num ))
32+
33+
34+ group_match ("(91)-986-015-2544" )
35+ group_match ("9860152544" )
36+ group_match ("(81)-123-456-7890" )
37+ group_match ("1234567890" )
38+ group_match ("(70)-2345-54354-65w56" )
39+ group_match ("325-654-6546" )
You can’t perform that action at this time.
0 commit comments