# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^5((0[0-9]|[3-5]\d)|(92)) \d{3} \d{4}$"
test_str = ("Turkcell\n\n"
"530 123 4567\n"
"531 123 4567\n"
"532 123 4567\n"
"533 123 4567\n"
"534 123 4567\n"
"535 123 4567\n"
"536 123 4567\n"
"537 123 4567\n"
"538 123 4567\n"
"539 123 4567\n\n"
"Türk Telekom Mobil\n\n"
"500 123 4567\n"
"501 123 4567\n"
"502 123 4567\n"
"503 123 4567\n"
"504 123 4567\n"
"505 123 4567\n"
"506 123 4567\n"
"507 123 4567\n"
"508 123 4567\n"
"509 123 4567\n\n"
"550 123 4567\n"
"551 123 4567\n"
"552 123 4567\n"
"553 123 4567\n"
"554 123 4567\n"
"555 123 4567\n"
"556 123 4567\n"
"557 123 4567\n"
"558 123 4567\n"
"559 123 4567\n\n"
"Vodafone\n\n"
"540 123 4567\n"
"541 123 4567\n"
"542 123 4567\n"
"543 123 4567\n"
"544 123 4567\n"
"545 123 4567\n"
"546 123 4567\n"
"547 123 4567\n"
"548 123 4567\n"
"549 123 4567\n\n"
"Globalstar\n\n"
"592 211 9999\n"
"592 212 0888\n\n"
"Teknomobil\n\n"
"592 113 0900\n"
"592 113 1900\n"
"592 113 2900\n"
"592 113 3900\n"
"592 113 4900\n"
"592 113 5900\n"
"592 113 6900\n"
"592 110 0900\n"
"592 110 1900\n"
"592 110 2900\n"
"592 110 3900\n"
"592 110 4900\n"
"592 110 5900\n"
"592 110 6900\n\n"
"TB Haberleşme\n\n"
"592 616 0900\n"
"592 616 1900\n"
"592 616 2900\n"
"592 616 3900\n"
"592 616 4900\n\n"
"Medium Telekom\n\n"
"592 216 9999")
matches = re.finditer(regex, test_str, 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