in reply to Re: regex, use of lookaround for whole word filtering
in thread regex, use of lookaround for whole word filtering

Thanks to ikegami (!), aquarium & dasgar for politely pointing me in the right direction. Thank you ww (assuming, that is, it is not some automatically generated reply which is triggered by the pattern /how should i/ig ) for warning me from the undesirable consequences my message may inflict (the worst of all is the re-reading the "how to pose a question" tutorial).

though not a one liner the following is simple to understand and does the trick

$_='nor neither nor'; my $cnt = 0; while ((/(.*?)nor/ig) ) { # =================== coarse match printf ("\n"); printf (STDOUT qq/\$\`:%s\n/,$`); printf (STDOUT qq/\$\&:%s\n/,$&); printf (STDOUT qq/\$\':%s\n/,$'); if ($1 !~ /\bneither\b/i){ # =========== finer match printf ("match no. %d: ",$cnt++); printf ("matched ok\n"); } else { printf ("match no. %d: ",$cnt++); printf ("no match\n"); }; }

Replies are listed 'Best First'.
Re^3: regex, use of lookaround for whole word filtering
by ikegami (Patriarch) on Aug 11, 2010 at 15:45 UTC
    You probably want \b around "nor" too, lest you get caught snoring on the job.