import re
regex = re.compile(r"(?:(f|F)((a|A)(X|x))?(?:\s?(\-|\:)?\s?))(?:\s?[0-9\+\.\(\)\/\\\-]\/?\\?\s?){7,30}(*SKIP)(*FAIL)|(?:\s?[0-9\+\.\(\)\/\\\-]\/?\\?\s?){7,30}")
test_str = ("PO BOX number 1234, CA - 3265 TEL: +1-200-200-2000 FAX: +1-200-200-2001 \n"
"PO BOX number 1234, CA - 3265 Service: +1-200-200-2002 \\ +1-200-200-2022 F : +1-200-200-2003 \n"
"PO BOX number 1234, CA - 3265 care: +1-200-200-2004 f : +1-200-200-2005 \n"
"PO BOX number 1234, CA - 3265 fire: +1-200-200-2006 fax : +1-200-200-2007 \n"
"PO BOX number 1234, CA - 3265 help: +1-200-200-2008 fax - +1-200-200-2009 \n"
"PO BOX number 1234, CA - 3265 fax : (+123)-4567890 \\ (+123)-4567891\n\n\n"
"(?:(f|F)((a|A)(X|x))?")
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