Search and select lines containing all keywords in notepad++
I am looking for a regular expression or any option… that allows me to search and select lines from notepad++, that contain all of the keywords.
The CAT and the DOG are friends
The CAT is named Purr.
The DOG is named Bark.
It is raining CATs and DOGs.
I need to select lines 1 and 4.
Do you know how to use google?
Thanks for the link
Alan, the first answer of this stackoverflow’s topic is really the best one ;-))
Indeed ! At first sight, although that, in OP text , word CAT always precedes the word DOG, I thought about the search regex, below :
However, the syntax
^(?=.*CAT)(?=.*DOG).*is really more elegant !
We can generalize to any number of words and, also, add conditions which should not occur ;-)) . For instance, the following regex would match all lines, with their line-breaks, which :
3expressions WORD_1 AND WORD_2 AND WORD_5
Does NOT contain the
2expressions WORD_4 OR WORD_6
So, it matches the lines
14, only, in the text :
This line 1 contains WORD_1 WORD_2 This line 2 contains WORD_1 WORD_3 WORD_5 This line 3 contains WORD_3 WORD_5 WORD_4 This line 4 contains WORD_1 WORD_5 This line 5 contains WORD_5 WORD_2 WORD_1 This line 6 contains WORD_2 WORD_1 WORD_6 WORD_5 This line 7 contains WORD_4 WORD_1 WORD_5 This line 8 contains WORD_2 This line 9 contains WORD_5 WORD_2 WORD_4 WORD_7 WORD_1 This line 10 contains WORD_1 WORD_6 WORD_2 This line 11 contains WORD_4 WORD_2 WORD_1, WORD_5 WORD_6 This line 12 contains WORD_7 WORD_2 WORD_5 WORD_1 This line 13 contains WORD_6 WORD_2 WORD_1 WORD_5 This line 14 contains WORD_1 WORD_5 WORD_8 WORD_2 WORD_3