javascript - JS regexp to match words, include words surrounded by spaces -


expression:

/(^|[^ \/?$])\b(foo)\b/g 

test string:

foo             - need 1 <div>foo</div>  - need 2  foo            - need 3  foo             - dont need foobar          - dont need /foo/           - dont need 

substitution:

$1bar 

need improve regexp work ex# 3. see demo

try (^|[^\/])\b(foo)\b , change substition $2bar


Comments