[英]Notepad++ `Find in Files` displays all results except a certain keyword
I am using notepad++ to search for certain keywords (using regular expression).我正在使用记事本++来搜索某些关键字(使用正则表达式)。 something like (word1|word2|this statement|another statement).
类似于 (word1|word2|this statement|another statement)。 It works but can I search and show all results except a certain keyword?
它有效,但我可以搜索并显示除某个关键字之外的所有结果吗? something like exclude the following words (exclude this|exclude this)?
诸如排除以下单词(排除此|排除此)之类的东西? For example, below.
例如,下面。
samedir\\File1.log相同目录\\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
samedir\\File2.log相同目录\\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
For example: I want to start a find in both files (on the same directory) but exclude the lines with excluding this
and exclude this
the results should show something like below例如:我想在两个文件中(在同一目录中)开始查找,但排除
excluding this
并exclude this
结果应显示如下所示
File1.log文件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
File2.log文件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
You can do this with a lookahead assertion:你可以用一个前瞻断言来做到这一点:
^(?!excluding this|exclude this)[^\\r\\n]*$
This will match entire lines as long as they don't contain excluding this
or exclude this
.这将匹配整行,只要它们不含有
excluding this
或exclude this
。
The key is the (?!)
part.关键是
(?!)
部分。 See http://www.regular-expressions.info/lookaround.html for more info.有关更多信息,请参阅http://www.regular-expressions.info/lookaround.html 。
You could try the regex like below to match all the lines which don't have exclude
or excluding this
strings.您可以尝试使用下面的正则表达式来匹配所有没有
exclude
或excluding this
字符串的行。
^(?!.*\bexclud(?:ing|e) this\b).+$
This (?!.*\\bexclud(?:ing|e) this\\b)
negative lookahead at the start asserts that there isn't a string exclude this
or excluding this
present on the the line in which we are going to match. (?!.*\\bexclud(?:ing|e) this\\b)
否定前瞻断言在我们要匹配的行上没有exclude this
或excluding this
的字符串。 That is , the above regex would match all the lines except the one which contains exclude this
or excluding this
也就是说,上面的正则表达式将匹配除了其中包含一个所有行
exclude this
或excluding this
I wanted to exclude one string and search for two strings in one line, so I used this regex:我想排除一个字符串并在一行中搜索两个字符串,所以我使用了这个正则表达式:
^(?!.*excludethisstring).*includethisstring1.*includethisstring2.*$
This will make it so that the one line searched MUST have the two strings included, if you want to search for either one of the lines:这将使搜索的一行必须包含两个字符串,如果您想搜索其中任何一行:
^(?!.*excludethisstring).*(includethisstring1|includethisstring2).*$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.