in reply to Pattern matching when there are exception strings

split on your exceptions and grep for your matches:
my $exceptions = qr/_ALPHA|#ALPHA|XL5 ALPHA/; my $keepers = qr/ALPHA|BETA/; print "Matched ($srch)!\n" if grep /$keepers/, split $exceptions, $src +h;

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Pattern matching when there are exception strings
by sauoq (Abbot) on Sep 21, 2005 at 13:59 UTC

    Note that this solution, the other one you provided, and my suggestion to use s///g on exceptions all have the flaw that they won't work if good strings can overlap bad ones. (I.e. if _ALPHA is an exception, but _ALPHALPHA should be a good match.)

    -sauoq
    "My two cents aren't worth a dime.";
    
      Strictly speaking, it wasn't specified whether an overlapping good and bad match is good or bad. As it happens alphabetical superstrings are always exceptions, when there is no whitespace breaking them up and I need to add this in - it also illustrates why it's nasty for a regexp:

      #more exceptions to all /MATCH/ strings: /\w+MATCH\W+/ or /\W+MATCH\w+/ or /\w+MATCH\w+/ ...

      Er, except that of course it doesn't like \W so anyway I'll have to borrow from some other solutions here which use the local negation operator.

      thanks for your input,

      the Moron

      Free your mind