Reputation: 110892
I'm looking for a JavaScript Regular Expression that will replace i
in sin(i/20*i)
but not in the i
in sin
. Using (\W)i
will always give me (i
in this case.
Upvotes: 0
Views: 50
Reputation: 354416
You can replace
\bi\b
which will require i
to stand alone (or at least not in a string of alphanumeric characters and underscores). The \b
is a zero-width assertion, as it matches a position between characters, so you don't capture more than you need.
The usual cautions apply. With only a single example it's hard to give a good solution that works for whatever data you want to throw it at. Adapt accordingly.
Upvotes: 5