I figured out how to check an OR case, preg_match( "/(word1|word2|word3)/i", $string );. What I can’t figure out is how to match an AND case. I want to check that the string contains ALL the terms (case-insensitive).
I figured out how to check an OR case, preg_match( /(word1|word2|word3)/i, $string ); .
Share
It’s possible to do an AND match in a single regex using lookahead, eg.:
however, it’s probably clearer and maybe faster to just do it outside regex:
or, if your target strings are as simple as
word1: