There's more than one way to do things | |
PerlMonks |
Re^2: Removing XML comments with regexby moritz (Cardinal) |
on Oct 24, 2007 at 19:31 UTC ( [id://646979]=note: print w/replies, xml ) | Need Help?? |
Test this regexes with
foo <!-- bar --> baz <!-- qox --> blurb - it removes too much.
You could do something like this: $xml =~ s/<!--.*?-->//g; Update: You can use the fact that '--' may not occur in xml comments: $xml =~ s/<!--(?:.(?<!--))*-->//g; Sadly lookarounds are error prone (from the programmer's side), so don't trust this regex unless you've tested it carefully. I don't think there is a big speed gain in it (if at all), I hope I find the tuits to benchmark it.
In Section
Seekers of Perl Wisdom
|
|