Exclude word from search filter
-
Hello,
I am using the Find feature of npp to find lines that have the word house in it, but I want to exclude versions of the word such as future house, tech house, and bass house.
What is the regular expression to search for lines containing house but also excluding the words future, tech, bass -
You can use negative lookbehinds to guarantee that “the text before
house
is notfuture
and is nottech
and is notbass
”:- FIND =
(?:(?<!future )(?<!tech )(?<!bass ))house
- Search Mode = Regular expression
You can combine that with your whole line matcher, which used to be something like
(?-s)^.*house.*$
to become:- FIND =
(?-s)^.*(?:(?<!future )(?<!tech )(?<!bass ))house.*$
… that will then match the whole line, not just the individual “house” on that line
----
Useful References
- FIND =