in reply to RegEx - comments should not matches


It looks like you are trying to read a C/C++ file.
Be carefull that you can have "doApply() // comment" in
the same line. I wrote a little example for you, that
will only ignore the line if the comment is in the
beginning of the line or after tabs/spaces.
#!/usr/bin/perl use strict; use warnings; if(!@ARGV) { die "program file.c\n"; } open(FILE,"<$ARGV[0]")|| die "Impossible to open $ARGV[0]\n"; my $ig=0; while(<FILE>) { if($_ =~ /\*\//) { $ig=0; next; } next if(($_ =~ /(^\s+|^\t+|^)\/\//)||($_ =~ /(^\s+|^\t+|^)\/\* +.+\*\//)); $ig=1 if($_ =~ /\/\*/); next if($ig == 1); print "$_"; } exit;


-DBC