Multiple words in any order using regex [duplicate]

Solution 1:

You can use

(?=.*test)(?=.*long)

Source: MySQL SELECT LIKE or REGEXP to match multiple words in one record

Solution 2:

Use a capturing group if you want to extract the matches: (test)|(long) Then depending on the language in use you can refer to the matched group using $1 and $2, for example.

Solution 3:

I assume (always dangerous) that you want to find whole words, so "test" would match but "testy" would not. Thus the pattern must search for word boundaries, so I use the "\b" word boundary pattern.

/(?i)(\btest\b.*\blong\b|\blong\b.*\btest\b)/

Solution 4:

without knowing what language

 /test.*long/ 

or

/long.*test/

or

/test/ && /long/

Solution 5:

Try this:

/(?i)(?:test.*long|long.*test)/

That will match either test and then long, or long and then test. It will ignore case differences.