import re
regex = re.compile(r"<a (?:(?!</a>).)*mailicon4\.gif.*?</a>", flags=re.DOTALL)
test_str = (" <a href='abc'>blah blah</a>\n"
" <a class=\"nonblock nontext\" id=\"u209382\" href=\"mailto:info@example.com\">\n"
" <!-- rasterized frame --><img class=\"temp_no_img_src\" id=\"u209382_img\" alt=\"\" width=\"66\" height=\"66\"\n"
" data-orig-src=\"images/mailicon4-u209382.png?crc=143036675\" src=\"images/mailicon4.gif?crc=4208392903\" /></a>\n"
" <a href='abc'>blah blah</a>\n\n")
match = regex.search(test_str)
if match:
print(f"Match 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