# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<a.*?(href=\x22.*?\x22).*?>"
test_str = "<p>just a bunch of text here<a data-sv-linklookup-id=\"https://www.somesite.com/somevalue/?i=632738&ver=html5\" data-sv-linklookup-type=\"plugins_nav_external_link\" href=\"https://www.somesite.com/somevalue/?i=632738&ver=html5\" target=\"_blank\">view it online</a> or request it through our<a data-sv-linklookup-id=\"5a8dad3e2f124e053ecfe720\" data-sv-linklookup-type=\"plugins_nav_navitem_primary_main\" href=\"https://www.somesite.com/plan-your-trip/free-visitor-guide/\" target=\"_self\" title=\"some title\">online form</a>. a lot more text here<a data-sv-linklookup-id=\"5a8dad402f124e053ecfebd2\" data-sv-linklookup-type=\"plugins_nav_navitem_primary_main\" href=\"https://www.somesite.com/\" target=\"_self\" title=\"some title\">some more text</a></p>"
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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