[英]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. 我想匹配word1或word的字符串,但像'this is a testword'这样的字符串不应该匹配。 I'm trying to do preg_match('/^\\b(word|word1)\\b/i',$string)
but no luck 我正在尝试做preg_match('/^\\b(word|word1)\\b/i',$string)
但没有运气
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. 请注意, ^
表示字符串的开头,因此您正在寻找以您提供的选项开头的内容。
如果从RegEx的开头删除^
,似乎工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.