PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Regex Groups
import re
data = ["Country: Germany, Capital: Berlin, Calling code: +49",
"Country: Spain, Capital: Madrid, Calling code: +34",
"Country: Italy, Capital: Rome, Calling code: +39",
"Country: India, Capital: New Delhi, Calling code: +91",
"Hello, this is not matching..."]
for d in data:
m = re.search(r"^Country: (\w+), Capital: ([\w\s]+), Calling code: (\+\d+)$", d)
if m:
print(m.groups())
else:
print("Regex mismatch.")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run