import re
regex = re.compile(r"\/tax-efficient-(guide|investing)|\/tax-raid-high-earners", flags=re.MULTILINE)
test_str = ("<!-- INSTAPAGE: Paths only -->\n"
"/\n"
"/tax-efficient-guide\n"
"/tax-efficient-investing\n"
"/tax-efficient-guide-download\n"
"/tax-raid-high-earners\n"
"/tax-raid-high-earners-download\n"
"/tax-efficient-investing-capital-gains\n"
"/tax-efficient-investing-capital-gains-download\n"
"/pb_iht_guide\n"
"/pb-iht-download\n"
"/iht-guide\n"
"/iht-guide-download\n"
"/inheritance-tax\n"
"/inheritance-tax-download\n"
"/iht-free-isa\n"
"/make-isa-iht-free\n"
"/iht-free-isa-download\n"
"/aim-isa-guide\n"
"/aim-isa-guide-download\n"
"/eis-factsheet\n"
"/EIS-factsheet-download\n"
"/seis-factsheet\n"
"/seis-factsheet-download\n"
"/vct-factsheet\n"
"/vct-factsheet-download\n"
"/eis-knowledge-intensive\n"
"/uktn-download\n"
"/free-research-report-octopus-titan\n"
"/free-research-report-octopus-titan-download\n"
"/investment-ideas\n"
"/investment-ideas-download\n"
"/isa-iht-free-report\n"
"/isa-iht-free-report-download\n\n"
"<!-- WWW SITE -->\n\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