如何使用
Regex查找以abc开头的每个字符串,以def结尾,但两者之间不包含123?
解决方法
你可以在这里使用否定前瞻.
^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