import re
regex = re.compile(r"[.!?]<\/h[1-6]>(*SKIP)(*FAIL)|<\/h[1-6]>")
test_str = ("<p>Today, not only we have so many breeds that are trained this and that.</p>\n\n"
"<h4><strong>We must add a dot after the closing strong</strong></h4>\n\n"
"<p>Hunting with your dog is a blah blah with each other.</p>\n\n"
"<h2>No need to change this one!</h2>\n\n"
"<p>Hunting with your dog is a blah blah with each other.</p>")
subst = ".$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