What is the regular expression to delete HTML comments?
I need to remove several thousand comments from an HTML document. The comments are in this form (multi-line):
<p>some HTML</p>
<!--
FOO
BAR
BLAH
-->
<p>more HTML</p>
What regular expression can I use in a find/replace to return this result:
<p>some HTML</p>
<p>mo开发者_如何学运维re HTML</p>
If you have Dreamweaver, the "Clean Up HTML/XHTML" command has an option to remove Non-Dreamweaver comments. That should take care of a problem like this very easily.
If you only want to remove comments in this particular format (and leave all other comments intact):
replace(/^<\!--.*?-->$/mg, "")
The .*? is non-aggressive match. "m" flag necessary to make it multi-line (so ^ and $ will match the beginning/end of lines respectively).
If you want to remove all comments:
replace(/<\!--.*?-->/g, "")
You shouldnt use Regex for this. Try the HTML agility pack instead.
HTML Agility Pack
精彩评论