I have this code
var str = "Some text :$0";
var i = 0;
alert(str.replace(new RegExp("\:\$" + i, "g"), 'here'));
see here.
Why is it not working? If I do it like this /\:\$:0/g
instead of using the RegExp
object then it works but I can't use a variable in the pattern that way. Whats wrong?