I'd like to match a 开发者_开发百科string for word1 or word but a string like 'this is a testword' should NOT give a match. I'm trying to do preg_match('/^\b(word|word1)\b/i',$string)
but no luck
I think your problem is the ^
at the start:
preg_match('/\b(word|word1)\b/i',$string);
Note that the ^
denotes the beginning of the string, so you are looking for something that starts with the options you are giving.
Seems to work fine if you remove the ^
from the beginning of your RegEx ..
精彩评论