Notepad++ search with a logical AND
Solution 1
Find -> Regular expression, then type
(CAT)(.*?)(ROAD)
Solution 2
If you are looking for a true &&
operation where a line contains both words in any order then you will want to match both of these lines:
The CAT goes up and down the ROAD.
The ROAD goes up and down the CAT. (poor cat)
In this case you will want to use:
^(?=.*\bCAT\b)(?=.*\bROAD\b).*$
Explanation:
-
^
start line -
$
end line -
?=
positive look ahead -
\b
word boundary. Not sure if you want this or not. Remove these if you want to match any part of word, e.g.TheCATgoes up and down theROAD
.
(?=)
is a positive look ahead. We have two such look aheads, one for anything (*
) followed by CAT and one for anything (*
) followed by ROAD. There is an implied &&
between the two lookaheads - both conditions must be satisfied.
Read up on lookarounds here
ihtus
Updated on August 17, 2022Comments
-
ihtus over 1 year
Using Notepad++ I need to find lines that would contain 2 keywords (both).
I've found how to combine 2 regex with a logical 'or' operator.
Example:
(searchword1)|(searchword2)
But how do I combine with logical 'and'?
Tried &, &&.. no success.
Example of input:
The CAT goes up and down the ROAD. The CAT goes up and down the CITY.
Search words:
CAT & ROAD
Expected result: line1