This should work for you. See Death to Dot Star! for details. Be careful on this one. It's really tricky.$text =~ s|/\* # First slash and star /* (?: # Non-backreferencing parentheses (?!\*/) # not a star slash */ . # ok to inch along )* # Zero or more \*/||sx; # Followed by a star slash */
With all due respect to kilinrax, his (her?) regex can fail under some circumstances:
This prints foo /* bar **/ baz. The extra asterisk at the end of the first C comment throws off the regex.my $text = 'foo /* bar **/ baz /* ack! ph! */'; $text =~ s| \/\* # '/*', escaped [^\*]* # 0 or more non-'*' characters \*\/ # '*/', escaped ||x; print $text;
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) RE: Multi Line c comments
by Ovid
in thread Multi Line c comments
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |