gpt4 book ai didi

正则表达式:检查 `abc`,然后检查 `def`,中间没有 `123`

转载 作者:行者123 更新时间:2023-12-01 09:57:16 24 4
gpt4 key购买 nike

如何使用 Regex 查找以 abc 开头,以 def 结尾,但中间不包含 123 的每个字符串?

最佳答案

您可以在此处使用Negative Lookahead

^abc(?:(?!123).)*def$

正则表达式

^              # the beginning of the string
abc # 'abc'
(?: # group, but do not capture (0 or more times)
(?! # look ahead to see if there is not:
123 # '123'
) # end of look-ahead
. # any character except \n
)* # end of grouping
def # 'def'
$ # before an optional \n, and the end of the string

关于正则表达式:检查 `abc`,然后检查 `def`,中间没有 `123`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23435397/

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