import re
regex = re.compile(r"<a[^>]*href\s*=(?<HRef>[^>]+)>")
test_str = ("<html><head>\n"
"<title>Simple</title>\n\n\n"
"</head>\n"
"<body>\n"
"<div id=\"Content\" style=\"padding: 5px;\">\n"
"<p><a href=\"http://confluence:8080/download/attachments/8618175/Text.txt?version=1&modificationDate=1484637732181\">Text.txt</a><br/>\n"
"<span class=\"image-wrap\" style=\"\"><img src=\"http://confluence:8080/download/attachments/8618175/add-button-blue-hi.png?version=1&modificationDate=1484562338796\" style=\"border: 1px solid black\" /></span><br/>\n"
"<span class=\"image-wrap\" style=\"\"><a class=\"confluence-thumbnail-link 300x200\" href='http://confluence:8080/download/attachments/8618175/attachment.jpg'><img src=\"http://confluence:8080/download/thumbnails/8618175/attachment.jpg\" style=\"border: 1px solid black\" /></a></span></p>\n"
"</div>\n"
"</body></html>")
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