import re
regex = re.compile(r"^(?P<Root>file\:\/\/\/(?:[A-Za-z]+):(?:\/|\\)|https\:\/\/)(?P<Relative>(?:(?:[^<>:\"\/\\|?*\n])+(?:\/|\\))+)(?P<File>(?:[^<>:\"\/\\|?*\n]+)(?:\.(?:pdf)))$", flags=re.MULTILINE)
test_str = ("file:///D:/Documents/My%20Documents/T09_27jun-17jul_V_Fro.pdf\n\n"
"file:///z:/Documents/My%20Documents/pdfs/eggs,%20milk,%20fruit.pdf\n\n"
"file:///zz:/Documents/My%20Documents/example.folder/icebreaker.pdf\n\n"
"file:///abv:/program%20shmogram%20(x86)/CoolTheVideoGameTheMovie/lewd.mods/uwuDialogueforFemales.pdf\n\n"
"file:///h:/Documents/My%20Documents/example.folder/New%20folder/ExamplE%20folder%203/very_cool_kanye.pdf\n\n"
"https://www.samsclub.com/savings/20230626/T09_27jun-17jul_V_Fro.pdf\n\n"
"https://whatkindofprefixisthis.RobertTheWebsite.io/AboutUs/Who-Da-frick_IS_Robert-anyways.pdf")
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