I've simplified the problem I ran into.
If I execute the following code in Chrome I get a strange behaviour:
var a = "$&";
var b = "aba";
var c = b.replace(/a/, a);
console.log(c); // expected output is: "$&b$&"
// but output is: "aba"
But if I execute the following code I get the expected output
var a = "c";
var b = "aba";
var c = b.replace(/a/, a);
console.log(c); // expected output is: "cbc"
// and output is: "cbc"
Any ideas how to solve this?
Is this a bug?
Do I have to escape the string in variable a in some ways?