import re
regex = re.compile(r"((?<=\<)[^>]+style=\")([^>\"]+)", flags=re.MULTILINE | re.IGNORECASE | re.UNICODE)
test_str = ("<p id=\"tem\" style=\"text-align: justify;\"><span style=\"font-size: 11pt;\" >hello world<br /></span></p>\n"
"<p style=\"text-align: justify;\">test text-align: justify;</p> style=\"text-align: justify;\"\n"
"<p > </p>\n"
"<p> </p>")
subst = "$1$2margin:0;"
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