如何使用Regex查找以abc
开头的所有字符串,以def
结尾,但中间不包含123
?
答案 0 :(得分:7)
您可以在此处使用否定前瞻。
^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