我正在尝试找到一个排除特定单词的正则表达式,但不包含包含它的单词。
例如,如果我们排除“home”一词
home --> NOT OK
homefree -> OK
freehome -> OK
有什么想法吗?
由于
答案 0 :(得分:3)
我建议您查看Rexegg — Word Boundaries。
如果你想匹配不包含" home"你可以这样做:
rsMatch
如果你想单独匹配单词:
preg_match_all('/^(?!.*\bhome\b).*$/im', $str, $matches);