Qteb
Qteb

Reputation: 533

JS regexp to match words, include words surrounded by spaces

Expression:

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

Test string:

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

Substitution:

$1bar

Need help to improve this regexp to work with ex# 3. See demo

Upvotes: 0

Views: 126

Answers (1)

Jerome Devost
Jerome Devost

Reputation: 59

Try (^|[^\/])\b(foo)\b and change your substition to $2bar

Upvotes: 1

Related Questions