import re
regex = re.compile((r"\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|\n"
r"2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|\n"
r"4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$"), flags=re.MULTILINE)
test_str = ("+962789719773\n"
"+9023847298\n"
"00962789719773\n")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html