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 reply to Re^2: Removing XML comments with regex
by moritz
in thread Removing XML comments with regex
by gasho
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |