表达式:
/(^|[^ \/?$])\b(foo)\b/g
测试字符串:
foo - need this 1
<div>foo</div> - need this 2
foo - need this 3
Foo - dont need this
foobar - dont need this
/foo/ - dont need this
替换:
$1bar
需要帮助来改进此正则表达式以与 ex# 3 一起使用。See demo
请您参考如下方法:
尝试 (^|[^\/])\b(foo)\b
并将替换更改为 $2bar