# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\.-?[_a-zA-Z]+[_a-zA-Z0-9-]*\s*\{(.*?)}"
test_str = ("<body> <style type=\"text/css\"> .csB51708B8{text-align:left;text-indent:0pt;margin:0pt 0pt 12pt 0pt;line-height:16.5pt} .csBBD4C4C1{color:#2B2E2F;background-color:transparent;font-family:'Lucida Sans Unicode';font-size:10.5pt;font-weight:normal;font-style:normal;} .csFC0FFCA7{text-align:left;margin:8pt 0pt 12pt 0pt;line-height:16.5pt;list-style-type:decimal;color:#2B2E2F;background-color:transparent;font-family:'Lucida Sans Unicode';font-size:10.5pt;font-weight:normal;font-style:normal} .csB4C51EC2{color:#2B2E2F;background-color:transparent;font-family:'Lucida Sans Unicode';font-size:10.5pt;font-weight:normal;font-style:normal;text-decoration: none;} .csC575EB8B{color:#0000FF;background-color:transparent;font-family:'Lucida Sans Unicode';font-size:10.5pt;font-weight:normal;font-style:normal;text-decoration: underline;} .cs67EAC646{text-align:left;margin:8pt 0pt 8pt 0pt;line-height:16.5pt;list-style-type:decimal;color:#2B2E2F;background-color:transparent;font-family:'Lucida Sans Unicode';font-size:10.5pt;font-weight:normal;font-style:normal} .cs896AFE57{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt;line-height:16.5pt} .csE2621F37{text-align:left;text-indent:0pt;margin:11pt 0pt 11pt 0pt;line-height:16.5pt} .cs2654AE3A{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt} .csC8F6D76{color:#000000;background-color:transparent;font-family:Calibri;font-size:11pt;font-weight:normal;font-style:normal;} .cs8D3F54E5{color:#000000;background-color:transparent;font-family:Verdana;font-size:8pt;font-weight:normal;font-style:normal;} </style> <p class=\"csB51708B8\"><span class=\"csBBD4C4C1\">\n"
"...\n"
"</body> ")
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