Notepad++ Find lines that contain multiple strings in any combination?

For example, in the following list, I want to find all lines that contain onkey AND tur AND .pdf, in any combination (stings in any order, repetitions allowed, but each must be present at least once in the line):

cat-dog-trutle-horse-horse-monkey.doc
fish-snail-monkey.txt
turtle-zebra-whale-monkey.doc
turtle-zebra-whale-zebra.pdf
turtle-zebra-whale-monkey.pdf
turtle-zebra-whale-monkey.png
turtle-zebra-whale-monkey-monkey.pdf--2

The answer should be:

turtle-zebra-whale-monkey.pdf
turtle-zebra-whale-monkey-monkey.pdf--2

This code does not handle different permutations. Any thoughts how to fix it?

(.*)onkey(.*)tur(.*).pdf(.*)
x Regular expression
1

1 Answer

You can usepositive lookahead(?=…) to assert that a given pattern can be matched. Place the anchor at the beginning of the string and one by one, in any order, look for a match of each of your strings.

It'll look something like this:

^(?=.*onkey)(?=.*tur)(?=.*pdf).*$

Ensure you're using the Regular expression mode without ". matches newline".

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like