简体   繁体   English

正则表达式否定前瞻以匹配 url

[英]Regex negative lookahead to match url

I'm trying to match urls /api/v1/users... /api/v1/other_stuff...我正在尝试匹配网址 /api/v1/users.../api/v1/other_stuff...

Except for /api/v1/users/invitation_register除了 /api/v1/users/invitation_register

I've been trying to use negative lookbehind我一直在尝试使用负面回顾

^\/api.*(?<!\binvitation_register\b)

and several similar constructs and have no idea how to actually do this.和几个类似的结构,但不知道如何实际做到这一点。 Any help would be more then welcome.任何帮助都会更受欢迎。

You can use this negative lookahead instead of lookbehind:您可以使用此否定前瞻而不是后视:

^\/api\/(?!v1\/users\/invitation_register\b).*

(?!v1\\/users\\/invitation_register\\b) is a negative lookahead that asserts that v1/users/invitation_register fails after /api/ . (?!v1\\/users\\/invitation_register\\b)是一个否定前瞻,断言v1/users/invitation_register/api/之后失败。

RegEx Demo正则表达式演示

If your intended match is always starting with /api/v1/... then you can use:如果您想要的匹配总是以/api/v1/...开头,那么您可以使用:

^\/api\/v1\/(?!users\/invitation_register\b).*

which asserts that users/invitation_register fails after /api/va/ .断言users/invitation_register/api/va/之后失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM