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--2The answer should be:
turtle-zebra-whale-monkey.pdf
turtle-zebra-whale-monkey-monkey.pdf--2This 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".