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

You have an answer... but had you read On asking for help and How do I post a question effectively?, you would have known what that your question might be ill-received:
  1. The Monastery is NOT a code writing service. Rather, it seeks to be a site to help you learn (cf, "feed a man a fish...." and similar). To that end, "how should I (write some particular code)" is a question that tends to receive disparaging replies... or guides like this on some of the most basic protocols here.
  2. If you pose your question -- with code (and data if relevant) -- to seek assistance on a particular issue that has you stumped, you will have learned something in the course of writing that code and exploring the related documentation and you'll usually find that the Monks will be generous with their time and expertise.
  • Comment on Re: regex, use of lookaround for whole word filtering

Replies are listed 'Best First'.
Re^2: regex, use of lookaround for whole word filtering
by yonatan (Novice) on Aug 11, 2010 at 10:51 UTC

    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"); }; }
      You probably want \b around "nor" too, lest you get caught snoring on the job.