Reputation: 7762
I am writing regex pattern for nginx rewrite rules to redirect the url. Here is string pattern which I would like to match and not-match.
Match url for below uri.
/abc/def
/abc/def/#
/abc/def#/
/abc/def/#/
Exclude the url if test
in the string.
/abc/def/test
/abc/def#/test
/abc/def/#/test
/abc/def/test/dsadasd
/abc/def#/test/dadsd
I have written below regex pattern but it is failing for two match highlighted in yellow
Any suggestions to fix this? Thanks !
Upvotes: 1
Views: 3636
Reputation: 521249
You could use this regex pattern:
^\/abc\/def(?!.*\btest\b).*$
This regex asserts that test
as a component does not appear anywhere in the path after the first two components. You could also match for \btest\b
, and reject any such matches.
Upvotes: 2