JavaScript RegExp in replace() not working : <p>I have this code</p>

<pre><code>var str = "Some text :$0";
var i = 0;

alert(str.replace(new RegExp("\:\$" + i, "g"), 'here'));
</code></pre>

<p>see <a href="https://jsfiddle.net/3zyr03h0/" rel="nofollow">here</a>.</p>

<p>Why is it not working? If I do it like this <code>/\:\$:0/g</code> instead of using the <code>RegExp</code> object then it works but I can't use a variable in the pattern that way. Whats wrong?</p>
