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

You could probably make the first regex use a non-greedy .*
I think that's the simpler approach rather than negative look behind and what not. The same can be applied to many other programming logic problems..useful sometimes to think about chunks of code logic or regex patterns as sets in finite space.
the hardest line to type correctly is: stty erase ^H
  • Comment on Re^2: regex, use of lookaround for whole word filtering

Replies are listed 'Best First'.
Re^3: regex, use of lookaround for whole word filtering
by ikegami (Patriarch) on Aug 11, 2010 at 03:45 UTC

    You could probably make the first regex use a non-greedy .*

    Wouldn't help.

    >perl -E"$_='nor neither nor'; say !/neither.*nor/ && /nor/ ?1:0" 0 >perl -E"$_='nor neither nor'; say !/neither.*?nor/ && /nor/ ?1:0" 0

    Non-greediness is very fragile and frequently misused.

      Two regexes with capturing in the first one, then:
      $test = "a nor b neither"; say $test =~ /(.*?nor)/i && $1 !~ /neither/i ? 1 : 0;