in reply to Re: Pattern matching when there are exception strings
in thread Pattern matching when there are exception strings

That wouldn't match "ALPHA" on a line by itself; it demands a non-# non-_ character before the ALPHA. If you do it this way you probably want a zero-width assertion.

My first thought is to do a global replacement of all the exceptions, to remove them from the data. Then search what's left for the strings you do want to count. Performance-wise I don't know how great this would be, but it's easier to read (and possibly easier to write if it needs to be automated for a large amount of search strings).

while(<>){ s/(?:_|#|XL5 )ALPHA//g; print if /ALPHA/; }

edit: davidrw beat me to it.

Replies are listed 'Best First'.
Re^3: Pattern matching when there are exception strings
by Roy Johnson (Monsignor) on Sep 21, 2005 at 13:45 UTC
    Splicing out things as you suggest would leave the possibility (however remote) that a false match would be created by the pasted-together remnants. Like if you removed "XL5 ALPHA" from "ALXL5 ALPHAPHA". See my split-and-grep recommendation for a similar technique that isn't subject to the pasting problem.

    Caution: Contents may have been coded under pressure.