繁体   English   中英

Notepad++`在文件中查找`显示除某个关键字之外的所有结果

[英]Notepad++ `Find in Files` displays all results except a certain keyword

我正在使用记事本++来搜索某些关键字(使用正则表达式)。 类似于 (word1|word2|this statement|another statement)。 它有效,但我可以搜索并显示除某个关键字之外的所有结果吗? 诸如排除以下单词(排除此|排除此)之类的东西? 例如,下面。

相同目录\\File1.log

This is line 1
This is line 2
This is line 3
exclude this
This is line 4
This is line 5
This is line 6
not excluded
excluding this

相同目录\\File2.log

This is line 1 1
This is line 2 1
This is line 3 1
exclude this
This is line 4 1
This is line 5 1 1
This is line 6 1
not excluded
excluding this

例如:我想在两个文件中(在同一目录中)开始查找,但排除excluding thisexclude this结果应显示如下所示

文件1.log

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
This is line 6
not excluded

文件2.log

This is line 1 1
This is line 2 1
This is line 3 1
This is line 4 1
This is line 5 1 1
This is line 6 1
not excluded

你可以用一个前瞻断言来做到这一点:

^(?!excluding this|exclude this)[^\\r\\n]*$

这将匹配整行,只要它们不含有excluding thisexclude this

关键是(?!)部分。 有关更多信息,请参阅http://www.regular-expressions.info/lookaround.html

您可以尝试使用下面的正则表达式来匹配所有没有excludeexcluding this字符串的行。

^(?!.*\bexclud(?:ing|e) this\b).+$

演示

(?!.*\\bexclud(?:ing|e) this\\b)否定前瞻断言在我们要匹配的行上没有exclude thisexcluding this的字符串。 也就是说,上面的正则表达式将匹配除了其中包含一个所有行exclude thisexcluding this

我想排除一个字符串并在一行中搜索两个字符串,所以我使用了这个正则表达式:

^(?!.*excludethisstring).*includethisstring1.*includethisstring2.*$

这将使搜索的一行必须包含两个字符串,如果您想搜索其中任何一行:

^(?!.*excludethisstring).*(includethisstring1|includethisstring2).*$

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM