import re
regex = re.compile(r"(?<FULL>^(?<PATH>(?:\/|\.|\.\.){0,2})(?<CAPTURE1>\/[^\/\s]+)?(?<CAPTURE2>\/[^\/\s]+)?(?<CAPTURE3>\/[^\/\s]+)?(?<CAPTURE4>\/[^\/\s]+)?(?<CAPTURE5>\/[^\/\s]+)?(?<CAPTURE6>\/[^\/\s]+)?(?<FILENAME>\/[^\/\s]+)$)", flags=re.IGNORECASE | re.MULTILINE)
test_str = ("./src/index.js\n\n"
"./src/index.js#Soda\n\n"
"./src/index.js?soda=fries\n"
"./src/index.js#soda?fries=hamburger\n"
"./src/index.js#soda?fries=hamburger&bag+o=chips\n"
"http://www.google.com/blugh/hello\n"
"https://www.google.com:8080/src/ui/template-management/create-template/versioning/version.js\n"
"http://localhost:8080/blugh/hello\n"
"../MyPath\n"
"This here is a normal sentence, though!\n"
"./src/ui/{FILE}.js[x]?\n"
"./src/ui/login.js\n"
"./src/ui/logout.js\n\n"
"./src/ui/{FILE}/{FILE}.js[x]?\n"
"./src/ui/ad-hoc-messages/ad-hoc-messages.js\n"
"./src/ui/editor/editor.jsx\n"
"./src/ui/select-interaction/select-interaction.jsx\n"
"./src/ui/template-management/template-management.js\n\n"
"./src/ui/{DIR}/{FILE}/{FILE}.js[x]?\n"
"./src/ui/ad-hoc-messages/send-ad-hoc-message/send-ad-hoc-message.js\n"
"./src/ui/admin-console/Department-management/Department-management.js\n"
"./src/ui/admin-console/tag-management/tag-management.js\n"
"./src/ui/template-management/create-template/create-template.js\n"
"./src/ui/template-management/create-template/versioning/version.js\n\n"
"./src/ui/{DIR}/{FILE}.js[x]?\n"
"./src/ui/shared/select-template-to-send.js\n"
" \n"
"/select-interaction\n"
"/template-management\n"
"/template-management/create-template\n"
"/template-management/edit-template\n"
"/ad-hoc-messages\n"
"/ad-hoc-messages/send-ad-hoc-mail\n"
"/admin-console/category-management\n"
"/admin-console/tag-management\n"
"/Logout")
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