samedi 9 novembre 2019

Regex: how to match every word from a group in any order?

So let's say I want to search for the words hamburger and steak. The regex should match/return true only when both words are found, in either order. i.e.

The would return true

I like hamburgers and steak
I like steak and hamburgers

While these would return false, since only one of the words is matched

I like hamburgers
I like stake

Hopefully someone can help me out with this. Ideally there is a simple solution to this, since these queries will be generated by PHP and the user could enter unlimited words to search for (as opposed to this example, where only 2 are used), so complex solutions could be difficult to implement/debug

Anyway, thanks in advance for any help :)

Aucun commentaire:

Enregistrer un commentaire