import re
regex = re.compile(r"(.*\d*[13579]\.article)|(.*[a-d|[f-m]$)", flags=re.MULTILINE)
test_str = ("*** Match odds or A-M\n"
"(.*\\d*[13579]\\.article)|(.*[a-d|[f-m]$)\n"
"https://edu.rsc.org/science-research/salt-crystal-grows-legs/4012581.article\n"
"edu.rsc.org/45.article\n"
"edu.rsc.org/weuvkee/a\n"
"edu.rsc.org/weuvkee/f\n\n\n"
"****** Don't match\n"
"https://edu.rsc.org/ideas/5-ways-to-explain-titration/4012500.article?utm_source=house-list&utm_medium=email&utm_campaign=monthly-alert\n"
"https://edu.rsc.org/feature/making-materials-from-biomass/4012606.article\n"
"https://edu.rsc.org/eic/classroy\n"
"https://edu.rsc.org/wibble/chips/stuff/science\n"
"edu.rsc.org\n\n\n\n"
"*** Match evens or N-Z\n"
"(.*\\d*[02468]\\.article)|(.*[n-z]$)\n"
"https://edu.rsc.org/ideas/5-ways-to-explain-titration/4012500.article?utm_source=house-list&utm_medium=email&utm_campaign=monthly-alert\n"
"https://edu.rsc.org/feature/making-materials-from-biomass/4012606.article\n"
"https://edu.rsc.org/eic/classroy\n"
"https://edu.rsc.org/wibble/chips/stuff/science\n\n"
"****** Don't match\n"
"https://edu.rsc.org/science-research/salt-crystal-grows-legs/4012581.article\n"
"edu.rsc.org/45.article\n"
"edu.rsc.org/weuvkee/a\n"
"edu.rsc.org/weuvkee/f")
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