Skip to content

Commit fcc986a

Browse files
author
Vimal A.R
committed
* Day 87 of #100DaysofCode
* Updated Day-087/escape-parantheses.py to print the groups in separate lines.
1 parent d80b25c commit fcc986a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Day-087/escape-parantheses.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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")

0 commit comments

Comments
 (0)