import re
regex = re.compile(r"(?:https?://(?:[1-3]\.alpha|[45]\.beta)\.com|(?:http://[6-7]\.beta|https://6\.alpha)\.org)", flags=re.MULTILINE)
test_str = ("http://1.alpha.com\n"
"http://2.alpha.com\n"
"http://3.alpha.com\n"
"https://1.alpha.com\n"
"https://2.alpha.com\n"
"https://3.alpha.com\n\n"
"http://4.beta.com\n"
"http://5.beta.com\n"
"https://4.beta.com\n"
"https://5.beta.com\n\n"
"http://6.beta.org\n"
"http://7.beta.org\n"
"https://6.alpha.org\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