How do I write a regular expression to match two given strings, at any position in the string?
For example, if I am searching for cat and mat
You can try:
\bcat\b.*\bmat\b
\b is an anchor and matches a word boundary. It will look for words cat and mat anywhere in the string with mat following cat. It will not match:
Therez caterpillar on the mat.
but will match
The cat slept on the mat in front of the fire
If you want to match strings which have letters cat followed by mat, you can try:
cat.*mat
This will match both the above example strings.