# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<!--block:(.*?)-->((?:(?:(?!<!--(.*?)-->).)|(?R))*?)<!--endblock-->"
test_str = ("<!DOCTYPE html><html><head><title>Crew Watch (Responses)</title>\n"
"<link href='/static/spreadsheets2/client/css/461985016-waffle_k_ltr.css' type='text/css' rel='stylesheet'><style type=\"text/css\">\n"
" html { overflow: visible; }\n"
" #sheets-viewport { overflow: auto; }\n"
" #sheets-viewport.widget-viewport { overflow: hidden; }\n"
" .grid-container { overflow: visible; background: white;}\n"
" .grid-table-container { overflow: visible; }\n"
" #top-bar {\n"
" background: url(\"//ssl.gstatic.com/docs/spreadsheets/publishheader.png\") repeat-x bottom;\n"
" margin: 0;\n"
" overflow: hidden;\n"
" }\n"
" #top-bar {\n"
" border-bottom: 1px solid #ccc;\n"
" padding: 6px 6px 0;\n"
" }\n"
" #doc-title { padding-bottom: 5px; }\n"
" #doc-title .name { font-size: 15px; }\n"
" #sheet-menu {\n"
" font-size: 13px;\n"
" margin: 6px 0 0;\n"
" padding: 0 0 5px;\n"
" }\n"
" #sheet-menu li {\n"
" display: inline;\n"
" list-style-type: none;\n"
" margin: 0;\n"
" padding: 5px 8px;\n"
" }\n"
" #sheet-menu li.active {\n"
" background-color: #fff;\n"
" font-weight: bold;\n"
" border: 1px solid #999;\n"
" }\n"
" #top-bar #sheet-menu li.active {\n"
" border-bottom: 0;\n"
" }\n"
" #sheet-menu a, #sheet-menu a:visited { color: #07c; }\n"
" .ritz .waffle .s0{text-align:left;color:#000000;background-color:#ffffff;font-family:arial,sans,sans-serif;font-size:10pt;vertical-align:bottom;white-space:nowrap;direction:ltr;padding:2px 3px 2px 3px;}.ritz .waffle .s1{text-align:right;color:#000000;background-color:#ffffff;font-family:arial,sans,sans-serif;font-size:10pt;vertical-align:bottom;white-space:nowrap;direction:ltr;padding:2px 3px 2px 3px;}</style><script type=\"text/javascript\">\n"
" var activeSheetId;\n\n"
" function switchToSheet(id) {\n"
" if (document.getElementById('sheet-menu')) {\n"
" document.getElementById('sheet-button-' + activeSheetId)\n"
" .className = '';\n"
" document.getElementById('sheet-button-' + id).className = 'active';\n"
" }\n\n"
" document.getElementById(activeSheetId).style.display = 'none';\n"
" document.getElementById(id).style.display = '';\n"
" activeSheetId = id;\n\n"
" // posObjs() is defined in embeddedObjectJs (see EmbeddedObjectHtmlBuilder.java)\n"
" posObjs();\n"
" return false;\n"
" }\n"
" \n"
" function init() {\n"
" var optPageSwitcher;\n"
" \n"
" function resize() {\n"
" var optTopBar = document.getElementById('top-bar');\n"
" var adjustedHeight = window.innerHeight - (optTopBar ? optTopBar.offsetHeight : 0);\n"
" var adjustedWidth = window.innerWidth;\n"
" var sheetsViewport = document.getElementById('sheets-viewport');\n"
" sheetsViewport.style.width = (adjustedWidth + 'px');\n"
" sheetsViewport.style.height = (adjustedHeight + 'px');\n"
" if (optPageSwitcher) {\n"
" optPageSwitcher.resize(adjustedWidth, adjustedHeight);\n"
" }\n"
" }\n"
" resize();\n"
" window.onresize = resize;\n"
" }\n"
" </script></head><body onload=init()><div id=\"top-bar\"><div id=\"doc-title\"><span class=\"name\">Crew Watch (Responses) : Form Responses 1</span></div></div><div id=\"sheets-viewport\"><div id=\"1416730418\" style=\"display:none;position:relative;\" dir=\"ltr\"><div class=\"ritz grid-container\" dir=\"ltr\"><table class=\"waffle\" cellspacing=\"0\" cellpadding=\"0\"><thead><tr><th class=\"row-header freezebar-vertical-handle header-shim row-header-shim\"></th><th id=\"1416730418C0\" style=\"width:150px\" class=\"header-shim\"></th><th id=\"1416730418C1\" style=\"width:150px\" class=\"header-shim\"></th><th id=\"1416730418C2\" style=\"width:150px\" class=\"header-shim\"></th><th id=\"1416730418C3\" style=\"width:150px\" class=\"header-shim\"></th><th id=\"1416730418C4\" style=\"width:150px\" class=\"header-shim\"></th><th id=\"1416730418C5\" style=\"width:150px\" class=\"header-shim\"></th><th id=\"1416730418C6\" style=\"width:150px\" class=\"header-shim\"></th><th id=\"1416730418C7\" style=\"width:150px\" class=\"header-shim\"></th><th id=\"1416730418C8\" style=\"width:150px\" class=\"header-shim\"></th></tr></thead><tbody><tr style='height:21px;'><th id=\"1416730418R0\" style=\"height: 21px;\" class=\"row-headers-background row-header-shim\"><div class=\"row-header-wrapper\" style=\"line-height: 21px;\">1</div></th><td class=\"s0\">Timestamp</td><td class=\"s0\">First Name</td><td class=\"s0\">Middle Name</td><td class=\"s0\">Last Name</td><td class=\"s0\">Date of Birth</td><td class=\"s0\">Street Address</td><td class=\"s0\">City</td><td class=\"s0\">State</td><td class=\"s0\">Zip Code</td></tr><tr><th style=\"height:4px\" class=\"freezebar-cell freezebar-horizontal-handle row-header-shim\"></th><td class=\"freezebar-cell\"></td><td class=\"freezebar-cell\"></td><td class=\"freezebar-cell\"></td><td class=\"freezebar-cell\"></td><td class=\"freezebar-cell\"></td><td class=\"freezebar-cell\"></td><td class=\"freezebar-cell\"></td><td class=\"freezebar-cell\"></td><td class=\"freezebar-cell\"></td></tr><tr style='height:21px;'><th id=\"1416730418R1\" style=\"height: 21px;\" class=\"row-headers-background row-header-shim\"><div class=\"row-header-wrapper\" style=\"line-height: 21px;\">2</div></th><td class=\"s1\" dir=\"ltr\">3/26/2014 21:33:20</td><td class=\"s0\" dir=\"ltr\">John</td><td class=\"s0\" dir=\"ltr\">Collier</td><td class=\"s0\" dir=\"ltr\">Armstrong</td><td></td><td></td><td></td><td></td><td></td></tr><tr style='height:21px;'><th id=\"1416730418R2\" style=\"height: 21px;\" class=\"row-headers-background row-header-shim\"><div class=\"row-header-wrapper\" style=\"line-height: 21px;\">3</div></th><td class=\"s1\" dir=\"ltr\">8/21/2014 0:56:02</td><td class=\"s0\" dir=\"ltr\">john</td><td class=\"s0\" dir=\"ltr\">collier</td><td class=\"s0\" dir=\"ltr\">armstrong</td><td class=\"s1\" dir=\"ltr\">1/10/1984</td><td class=\"s0\" dir=\"ltr\">4720 SW 21st St.</td><td class=\"s0\" dir=\"ltr\">Topeka</td><td></td><td class=\"s1\" dir=\"ltr\">66604</td></tr><tr style='height:21px;'><th id=\"1416730418R3\" style=\"height: 21px;\" class=\"row-headers-background row-header-shim\"><div class=\"row-header-wrapper\" style=\"line-height: 21px;\">4</div></th><td class=\"s1\" dir=\"ltr\">9/11/2014 0:56:28</td><td class=\"s0\" dir=\"ltr\">Conner</td><td class=\"s0\" dir=\"ltr\">Goss</td><td class=\"s0\" dir=\"ltr\">Griffin</td><td class=\"s1\" dir=\"ltr\">8/31/1992</td><td></td><td class=\"s0\" dir=\"ltr\">Topeka</td><td></td><td></td></tr></tbody></table></div></div></div>\n"
"<script type='text/javascript'>\n"
"function posObj(sheet, id, row, col, x, y) {\n"
" var r = document.getElementById(sheet+'R'+row);\n"
" var c = document.getElementById(sheet+'C'+col);\n"
" if (r && c) {\n"
" var s = document.getElementById(id).style;\n"
" var t = y;\n"
" while (r) {\n"
" t += r.offsetTop;\n"
" r = r.offsetParent;\n"
" }\n"
" var l = x;\n"
" while (c) {\n"
" l += c.offsetLeft;\n"
" c = c.offsetParent;\n"
" }\n"
" s.left = l + 'px';\n"
" s.top = t + 'px';\n"
" s.display = 'block';\n"
" s.border = '1px solid #000000';\n"
" }\n"
"};\n"
"function posObjs() {\n"
"};\n"
"posObjs();</script>\n"
"<script type=\"text/javascript\">activeSheetId = '1416730418'; switchToSheet('1416730418');</script></body></html>")
matches = re.search(regex, test_str, re.DOTALL)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.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