【发布时间】:2018-03-11 12:46:52
【问题描述】:
下面是我的句子数组
$strings = [
"I want to match docs with a word New",
"But I don't want to match docs with a phrase New York",
"However I still want to match docs with a word New which has a phrase New York",
"For example let's say there's a New restaraunt in New York and I want this doc to be matched."
]
我想将上面的句子与单词 new 字符串匹配。但我不想匹配 new 后跟 york 的句子。我希望能够匹配任何单词A 前面/后面没有单词B 在一些小的单词距离N 内。不在“A”旁边。
如何使用正则表达式达到预期效果?
【问题讨论】:
-
使用负前瞻
(?!)