Reputation: 111
I am using notepad++ to search for certain keywords (using regular expression). something like (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
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
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
File1.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
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
Upvotes: 1
Views: 3039
Reputation: 1
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).*$
Upvotes: 0
Reputation: 174796
You could try the regex like below to match all the lines which don't have exclude
or excluding this
strings.
^(?!.*\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. That is , the above regex would match all the lines except the one which contains exclude this
or excluding this
Upvotes: 1
Reputation: 864
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
.
The key is the (?!)
part. See http://www.regular-expressions.info/lookaround.html for more info.
Upvotes: 2