How to match multiple words in regex How to match multiple words in regex javascript javascript

How to match multiple words in regex


Use lookahead assertions:

^(?=.*advancebrain)(?=.*com_ixxochart)(?=.*p=completed)

will match if all three terms are present.

You might want to add \b work boundaries around your search terms to ensure that they are matched as complete words and not substrings of other words (like advancebraindeath) if you need to avoid this:

^(?=.*\badvancebrain\b)(?=.*\bcom_ixxochart\b)(?=.*\bp=completed\b)


^(?=.*?p=completed)(?=.*?advancebrain)(?=.*?com_ixxocart).*$

Spent too long testing and refining =/ Oh well.. Will still post my answer


Use lookahead:

(?=.*\badvancebrain)(?=.*\bcom_ixxocart)(?=.*\bp=completed)

Order won't matter. All three are required.