开发者

PHP match multiple whole words in regex

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 ..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜