in reply to How do I match a expression start with $a and not contain $b after $a

/$a(?!.*$b)/

I will have to kill those who comment on my usage of the dot star :)
  • Comment on Re: How do I match a expression start with $a and not contain $b after $a
  • Download Code

Replies are listed 'Best First'.
Re (tilly) 1: Answer: How do I match a expression start with $a and not contain $b after $a
by tilly (Archbishop) on Jan 28, 2002 at 18:41 UTC
    At the risk of death, you need a /s modifier if you want the intermediate junk to be able to include returns.

    Also you should be using \Q and \E escapes.

    /\Q$a\E(?!.*\Q$b\E)/s
    (The mistake of using $a and $b for normal use was the fault of the questioner, and not you.)
Re: Re: How do I match a expression start with $a and not contain $b after $a
by Anonymous Monk on Jan 29, 2002 at 06:29 UTC
    That regex will match "foobarfoo" if $a = "foo" and $b = "bar", but it shouldn't.

    See this node.

    -Anomo