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.
I’m looking for a JavaScript Regular Expression that will replace i in sin(i/20*i) but
Share
You can replace
which will require
ito stand alone (or at least not in a string of alphanumeric characters and underscores). The\bis 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.