PHP matches multiple integer words in a regular expression

I would like to match a string for word1 or word, but a string like "this is a test word" should NOT match. I'm trying to do preg_match('/^\b(word|word1)\b/i',$string)but no luck

+3
source share
2 answers

This seems like normal if you remove ^from the beginning of your RegEx ..

+1
source

I think your problem in the beginning ^:

preg_match('/\b(word|word1)\b/i',$string);

Note that this ^marks the beginning of a line, so you are looking for something that starts with the parameters you give.

+2
source

All Articles