Is there another way?
Remove comments from the input before matching.
For trivial code containing only // comments (not /* */) and without string constants containing //, the following should do the trick:
#!/usr/bin/perl use strict; use warnings; while (<>) { chomp; my $orig=$_; s|//.*||; # strip comments if (/\b(printf|scanf|open|close|read|write)\b/) { print "Found keyword '$1' in '$_'.\nOriginal line: '$orig'\n"; } }
Alexander
In reply to Re: Capture uncommented keywords
by afoken
in thread Capture uncommented keywords
by ExReg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |