gpt4 book ai didi

Expression in regex with exception [duplicate](正则表达式中的表达式出现异常[重复])

转载 作者:bug小助手 更新时间:2023-10-24 21:45:02 34 4
gpt4 key购买 nike




I would like to match all expressions that start with /api, for example:

我希望匹配所有以/api开头的表达式,例如:


/api/clients
/api/products
/api/documents
/api/login

but I should not match the expression /api/login.

但我不应该匹配表达式/api/login。


What regex could I use for this case?

对于这种情况,我可以使用什么正则表达式?


更多回答
优秀答案推荐

Using negative look-ahead:

使用消极的前瞻性:


/api/(?!login).*

Online Demo


The regular expression matches as follows:
































Node Explanation
/api/ '/api/'
(?! look ahead to see if there is not:
login 'login'
) end of look-ahead
.* any character except \n (0 or more times (matching the most amount possible))

更多回答

Perhaps unnecessary, but to be strict: (?!login$)

也许没有必要,但要严格:(?!LOGIN$)

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com