# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?:^|\s)(((?:\+|0{2})(?:49|43|33)[-\. ]?|0)([1-9]\d{1,2}[-\. ]?|\([1-9]\d{1,2}\)[-\. ]?)(\d{6,9}|\d{2,3}[-\. ]\d{4,6}))"
test_str = ("+33 100 000 0000\n"
"000-000-0000\n"
"000 000 0000\n"
"000.000.0000\n\n"
"12000-000-000012\n"
"12000 000 000012\n"
"12000.000.000012\n\n"
"0049-000-0000\n"
"000 000 0000\n"
"000.000.0000\n\n\n"
"(000)000-0000\n"
"(000)000 0000\n"
"(000)000.0000\n"
"(000) 000-0000\n"
"(000) 000 0000\n"
"(000) 000.0000\n\n"
"12(000)000-000012\n"
"12(000)000 000012\n"
"12(000)000.000012\n"
"12(000) 000-000012\n"
"12(000) 000 000012\n"
"12(000) 000.000012\n\n"
"000-0000\n"
"000 0000\n"
"000.0000\n"
"0000000\n"
"(100)0000000\n\n"
"12000-000012\n"
"12000 000012\n"
"12000.000012\n"
"12000000012\n"
"12(000)000000012\n\n"
"+28 100 000 0000\n"
"+33 000 000 0000\n"
"+33 100 000 0000\n"
"+49 100 000 0000\n"
"+43 100 000 0000\n"
"+43.100.000.0000\n"
"+43-100-000-0000\n"
"+43 100 000 0000\n"
"+43.100.000.0000\n"
"+43-100-000-0000\n"
"+433 100 000 0000\n"
"+433.100.000.0000\n"
"+433-100-000-0000\n"
"+433000000000\n"
"0043 1000000000\n"
"0043 100000000000023\n"
"0043 100000\n"
"0043 100000000\n"
"0043 100 00 00000\n"
"0043 100 000 0000\n"
"0043-100-000-0000\n"
"00431000000000\n"
"0000-000-000-0000\n"
"00000000000000\n"
"+43 (100)000 0000\n"
"0043 (100)000-0000\n"
"0043(100)000-0000\n"
"0000 (100)000-0000\n"
"0000(100)000-0000\n"
"+43 (100) 000 0000\n"
"0043 (100) 000-0000\n"
"0043(100) 000-0000\n"
"0000 (100) 000-0000\n"
"0000(100) 000-0000\n"
"+43 (10)000 0000\n"
"0043 (10)000-0000\n"
"0043(10)000-0000\n"
"0000 (10)000-0000\n"
"0000(10)000-0000\n"
"+43 (10) 000 0000\n"
"0043 (10) 000-0000\n"
"0043(10) 000-0000\n"
"0000 (10) 000-0000\n"
"0000(10) 000-0000\n\n"
"0662 874278\n"
"0676 7359567\n\n"
"0343545435343\n\n"
"06700000023\n\n"
"12+43 100 000 000012\n"
"12+43.100.000.000012\n"
"12+43-100-000-000012\n"
"12+43100000000012\n"
"120043 100000000012\n"
"120043-100-000-000012\n"
"120043100000000012\n"
"12+43 (100)000 000012\n"
"120043 (100)000-000012\n"
"120043(100)000-000012\n\n"
"+49 10 000000\n"
"(000) 0000-0000\n"
"(0000) 0000-0000\n"
"(00000) 000-0000\n"
"(030000) 00-0000\n"
"01200-0000000\n"
"0137-000 0000000\n"
"01500-0000000\n"
"0160-0000000\n"
"0170-0000000\n"
"032-000000000\n"
"0700-0000000\n"
"0800-0000000\n"
"0900-0-000000\n\n\n\n"
"0000000000000\n"
"0000000000000\n\n"
"120000000000000\n"
"120000000000000\n\n"
"+00+00 000 0000\n\n"
"2013 175000km\n"
"019 55000km")
matches = re.finditer(regex, test_str, re.UNICODE | re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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