import re
regex = re.compile(r"\s?on\w+=\"[^\"]+\"\s?")
test_str = ("<body>\n"
"<script src=\"...\">\n\n"
" </script>\n"
"<div onresize=\"CreateFixedHeaders()\" onscroll=\"CreateFixedHeaders()\" id=\"oReportDiv\" style=\"overflow:auto;WIDTH:100%\">\n\n"
"<script type=\"text/javascript\" language=\"javascript\">\n\n"
"//<![CDATA[\n\n"
"function CreateFixedHeaders() {}//]]>\n"
"</script>\n"
"<script>\n\n"
" var ClientReportfb64a4706a3749c484169e...\n"
" </script>\n"
"</body>")
subst = ""
result = regex.sub(subst, test_str)
if result:
print(result)
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