phpregexstring-matchingcpu-wordword-boundaries

preg_match for multiple words


I want to test a string to see it contains certain words.

i.e:

$string = "The rain in spain is certain as the dry on the plain is over and it is not clear";
preg_match('`\brain\b`',$string);

But that method only matches one word. How do I check for multiple words?


Solution

  • Something like:

    preg_match_all('#\b(rain|dry|clear)\b#', $string, $matches);