Javascript JS regexp匹配单词,排除斜杠包围的单词
此regexp在PHP中工作:Javascript JS regexp匹配单词,排除斜杠包围的单词,javascript,regex,Javascript,Regex,此regexp在PHP中工作: (?<![\/?$])\bfoo\b (? 我需要让它在JS中工作,所以 foo - need this <div>foo</div> - need this Foo - dont need this foobar - dont need this /foo/ - dont need this foo-需要这个吗 福-需要这个吗 福-不需要这个 foobar-不需要
(?<![\/?$])\bfoo\b
(?
我需要让它在JS中工作,所以
foo - need this
<div>foo</div> - need this
Foo - dont need this
foobar - dont need this
/foo/ - dont need this
foo-需要这个吗
福-需要这个吗
福-不需要这个
foobar-不需要这个
/foo/-不需要这个
更新:>解决方案
您现在可以使用它并抓取组
。请参阅演示
@Qteb这就是我写的原因,抓取组1
而不是匹配
。我不明白你的意思,你的例子不正确->@Qteb在右边看到…你可以看到你需要抓取的组…还有为什么'foo'无效?当我尝试使用替换时,它的替换不正确匹配,你能修复吗它?@Qteb它工作正常。你还想要什么结果
(?:^|[^\/?$])(\bfoo\b)