如何使用 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/