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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.