zend regex route with negative lookahead -
i'm trying write regex route in zend (1.11) matches urls ending in /foo not if start /bar e.g.
/foo - match /any/words/foo - match /any/words - no match (doesn't end in /foo) /any/words/barfoo - no match (doesn't end in /foo) /bar/foo - no match (starts /bar) /bar/any/words/foo - no match (starts /bar)
my regext route looks this:
'^foo$|^(?!/bar/).+/foo$'
but find matches ending in /foo, if starts /bar.
you need negative lookahead
lucky you, have 1 in pocket. try this:
^(?!/bar).*/foo$
see matches in demo.
- the
^
anchor asserts @ beginning of string - the negative lookahead
(?!/bar)
asserts follows not/bar
.*
matches characters (dot character except newlines, star repeats 0 or more times)/foo
matches/foo
- the
$
anchor asserts @ end of string
reference
Comments
Post a Comment