您的位置:首页 > 其它

不包含特定字符串的匹配

2015-12-31 12:33 369 查看
正则表达式匹配不包含特定字符串的文本,相信很多初学者都会范难(特指本人)。

下面找到一个匹配:

^((?!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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: