开发者

Regular Expression Exact Keyword Exclusion

开发者 https://www.devze.com 2023-01-08 22:42 出处:网络
Hi guys I am looking for a regular expression which will not match any given string that is exactly equal to a few keywords I will determine manually.

Hi guys I am looking for a regular expression which will not match any given string that is exactly equal to a few keywords I will determine manually.

The purpose is to edit my urlrewrite.xml which can accept regexps in following format

<rule>
     <from>^/location/([A-Z]+)/name/([A-Z]+)</from>
     <to>/login?name=$2&location=$1</to>
</rule>

For example I want to redirect everything after / which is not 'login' and 'signup' to another page. I am trying following ones but none satisfies my request.

^/(?!(login|signup).*开发者_Python百科
^/(?!(login|signup)[A-Za-z0-9]+

Because I want it to match only if input is exactly 'login' or 'signup' however, it declines 'loginblabla', too.

Any solutions are highly appreciated. :)


You need to add a $ anchor at the end of the lookahead:

^/(?!(login|signup)$)(.+)

Now anything that isn't exactly login or signup will be captured in group $1.

0

精彩评论

暂无评论...
验证码 换一张
取 消