Matching between comments

Subscribe to Matching between comments 3 posts, 2 voices

 
bobielawlintine Scriptwright

What would be the best way of matching everything between two comments and replacing it with a line of html?

So,

<!-- comment -->
...
lots of useless markup and stuff here
...
<!-- / comment -->

would become

<!-- comment -->
Inserted line here.
<!-- / comment -->

 
gremon User

I've been trying to do this to remove some incredibly annoying sigs. They are surrounded by comments like shown above. Could someone help me with the regular expression for selecting between two comments? It works when I test it here (http://www.regular-expressions.info/javascripte...) but not in my GreaseMonkey script.
Or is there a better way?

var expression = new RegExp("<!-- sig -->.*<!-- / sig -->", "g");
var replacement = "<br/><br/><p>__________(sig removed)__________</p>";
document.body.innerHTML = document.body.innerHTML.replace(expression, replacement);

 
gremon User

To answer my own question, the regex should be:

"<!-- sig -->((.|\n)*?)<!-- / sig -->"