RegEx ReWrite URL matches all expressions if not exist

I am currently rewriting the URL, however my RegEx expression catches a directory that I want to ignore.

Rewrite rule

^people/([A-Za-z0-9\-\_]+)/?$ 

... captures everything that matches. However, I would like to exclude the People_Search directory, for example ...

 /people/John_Smith 

... will pass, but

 /people/People_Search 

... should not be assumed.

This is the only term I want to find, so if it exists anywhere on the line, I want to ignore it.

Any ideas?

+4
source share
2 answers

There is a thing in Regex called β€œnon-exciting negative expectation,” which basically says β€œdoesn't match the following.” It looks like this:

 ^people/(?!People_Search)([A-Za-z0-9\-\_]+)/?$ 

Whether this can be used depends on the rewriting mechanism used and the level of support for regular expressions that are included in it. I would expect most common authors to rewrite this.

FYI: There are also negative statements of lookbehind (? <!), As well as lean versions of lookahead (? =) And lookbehind (? <=) Requests.

Tutorial: http://www.regular-expressions.info/lookaround.html

+7
source
 ^people/(?!People_Search)([A-Za-z0-9\-\_]+)/?$ 

Negative forecast to prevent People_Search matching after people/

+1
source

Source: https://habr.com/ru/post/1303737/


All Articles