[Solved] How to check specific phrases in text are present with regex


I found a solution that works, after trying alot of different things

(\bquick brown\b).*(\bover the\b)

It has a match on

“The quick brown fox jumps over the lazy dog, bla bla, something
something”

But not

“The quick brown fox jumps over something the lazy dog, bla bla,
something something”

And not

“The quick brownest fox jumps over the lazy dog, bla bla, something
something”

If you don’t care about the order of the phrases you can use this

(\bquick brown\b).*(\bover the\b)|(\bover the\b).*(\bquick brown\b)

The expression checks if quick brown and over the is there with anything in between.

You can also do

(\bquick brown\b).+?(\bover the\b)

That will give multiple matches if quick brown and over the is there multiple times.

In my case it makes no difference but it might for others

2

solved How to check specific phrases in text are present with regex