I want to remove HTML comments from an html text
<h1>heading</h1> <!-- comment-with-hyphen --> some text <-- con --> more text <hello></hello> more text
should result in:
<h1>heading</h1> some text <-- con --> more text <hello></hello> more text
Finally came up with this option:
re.sub("(<!--.*?-->)", "", t)
Adding the ?
makes the search non-greedy and does not combine multiple comment tags.
You shouldn't ignore Carriage return.
re.sub("(<!--.*?-->)", "", s, flags=re.DOTALL)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With