I am replacing a bunch of regular expression values with a dollar amount. The problem is that in IE, if I try to replace with the number $0 (or, theoretically, $1 - $9 ), the replacement never occurs, because it tries to replace a non-existent group:
'foo'.replace(/f/g, '$0');
I want the result of this replacement to be "$ 0oo", which is in Chrome and FF, but not IE9 (I have not tried other versions of IE).
Chrome and FF have a “problem” with the following: I cannot figure out how to replace the literal $1 :
'foo'.replace(/(f)/g, '$1')
source share