in reply to RegEx - comments should not matches
$string !~ m{^/[*/]}; # ^-beginning of the line, /- a slash [*/]-character class containing * and /
See perldoc perlre.
Update: !~ negates the match.
Update2: Thanks to Corion who pointed out that my approach didn't catch multiple line comments.
# a loop could do it like this:
$block_comment = 0; while ( <INPUT> ) { if ( m{^//} ) { next; } elsif ( m{^/\*} ) { $block_comment = 1; next; } # start block elsif ( m{^\*/} ) { $block_comment = 0; next; } # end block elsif ( $block_comment) { next; } # inside block else { ... do something with the line, that is no comment ... } }
Cheers, Sören
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RegEx - comments should not matches
by Chief of Chaos (Friar) on Jul 13, 2004 at 12:13 UTC |