import re
regex = re.compile(r"<div\s\w{5}=\"print[^>]*?>[\s\S]*?<\/div>", flags=re.IGNORECASE)
test_str = ("<div class=\"print\">\n"
" <a href=\"javascript:window.print();\" title=\"Print denne side\"><span class=\"print-btn icon\">P</span> Print denne side</a>\n"
" </div>\n"
"<div source=\"\">\n"
"<div>")
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