Having both a string and a message:
str = "Test $0 $1 $2";
message = "Hi %2 Hello %2" ;
The goal is to replace all occurrences of %2
with str
in the message using RegExp, like so:
message = message.replace(new RegExp("%2" , "g"), str);
While this works as expected in Chrome and Firefox:
message = "Hi Test $0 $1 $2 Hello $0 $1 $2"
In Internet Explorer 11, an issue arises where the value of the message is incorrect:
message = "Hi Test %2 $1 $2 Hello %2 $1 $2"
It seems that in IE11, the substitution is not replacing $0
(a substring of str
) properly. Any suggestions on how to fix this would be greatly appreciated.