正则表达式匹配不包含特定字符串的文本,相信很多初学者都会范难(特指本人)。
下面找到一个匹配:
^((?!string).)*$
其中 string 是要排除的字符串。
文本如下:
# particular features to be enabled - so if something's not working as # you might expect,make sure that you have specifically enabled it # below. # # all# DocumentRoot: The directory out of which you will serve your # documents. By default,all requests are taken from this directory,but # symbolic links and aliases may be used to point to other locations. #(呵呵, 偷了个懒,随手截了httpd.conf的内容)
配置所有不包含 "all"的行,匹配结果如下:
除了红色下划线标注的行都匹配到了
参考文章:
http://www.vaikan.com/regular-expression-to-match-string-not-containing-a-word/
原文链接:https://www.f2er.com/regex/359661.html