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
    Hi,
    if I process this, it would not match the
    commented line with doWhatEver().
    But thanks.
    CoC
    #!/usr/local/bin/perl -w while (<DATA>) { if ( $_ !~ m{^/[*/]} ) { print $_; } } __DATA__ doApply() // doNotApply() /* doWhatEver() */ Test4()

    will show :
    huxl:~>./tst.pl doApply() doWhatEver() */ Test4()