【发布时间】:2014-02-22 06:18:37
【问题描述】:
我有这个正则表达式
(?:$|^| )(one|common|word|or|another)(?:$|^| )
除非两个单词彼此相邻,否则匹配得很好。
One one's more word'word common word or another word more another
More and more years to match one or more other strings
And common word things and or
在上面它匹配第二行的one,但不匹配它旁边的or。对于 common 和 word int 第三行也是如此。
实时示例:http://regex101.com/r/hV3wQ3
我认为这与不匹配组的号码有关。但是,我不确定如何实现匹配所有单词列表且周围没有任何字符的最终目标。
我不想匹配one's 中的one 或word'word 中的单词。
【问题讨论】:
标签: regex pattern-matching regex-group