簡體   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