import re
regex = re.compile(r"(?i)(href=\"[a-zA-Z\/-]+\.x?html#)(?-i)([a-z]+?_[-a-z]*)([A-Z])", flags=re.MULTILINE)
test_str = ("<a href=\"/premium-classic/before-you-start.xhtml#sub_InstallingLightroom\">Installing Lightroom</a>\n"
"<a href=\"/premium-classic/before-you-start.xhtml#box_MultipleComputers\">Multiple Computers</a>\n"
" <a href=\"/premium-classic/before-you-start.xhtml#sub_KeepingLightroomUpdated\">Keeping Lightroom Updated</a>\n"
"<a href=\"/premium-classic/managing-your-photos.xhtml#sub_ManagingFoldersInLightroomAndOnTheHardDrive\">Managing Folders in Lightroom and on the Hard Drive</a>\n"
"<a href=\"/premium-classic/managing-your-photos.xhtml#sub_ChangingTheFolderStructure\">Changing the Folder Structure</a>")
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