表达式:
/(^|[^ \/?$])\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
需要帮助来改进此正则表达式以使用前#3。See demo
答案 0 :(得分:1)
尝试(^|[^\/])\b(foo)\b
并将您的替换更改为$2bar