# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<span class=\"sense\"><span class=\"bld\">A<\/span>(?s)(?!.*<span class=\"bld\">)"
test_str = ("<span class=\"sense\"><span class=\"bld\">A</span> [[lay bare at the side]], [[expose]], τι τῆς πλευρᾶς <span class=\"bibl\">Arr. <span class=\"title\">Tact.</span>40.5</span>, cf. <span class=\"bibl\">D.C.49.6</span> (Pass.). </span><span class=\"sense\"><span class=\"bld\">2</span> metaph., [[lay bare]], [[disclose]], τὸν πάντα λόγον <span class=\"bibl\">Hdt.1.126</span>, cf. <span class=\"bibl\">8.19</span>, <span class=\"bibl\">9.44</span>; τὸ βούλευμα <span class=\"bibl\">Conon 50</span>:—Pass., <b class=\"b3\">παρεγυμνώθη διότι</b>… <span class=\"bibl\">Plb.1.80.9</span>.</span>\n\n\n"
"<span class=\"sense\"><span class=\"bld\">A</span> [[lay bare at the side]], [[expose]], τι τῆς πλευρᾶς <span class=\"bibl\">Arr. <span class=\"title\">Tact.</span>40.5</span>, cf. <span class=\"bibl\">D.C.49.6</span> (Pass.).")
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