Consider the code below:
var my_string = "aicId";
var my_pattern = "i";
var my_regex = new RegExp(my_pattern,"gi");
var my_result = my_string.replace(my_regex,"x$&y");
alert (my_result);
This would return:
axiycxIyd
Now, what if I want it to return this:
ax$&ycx$&yd
What do I need to do?
I tried to escape them like this:
var my_result = my_string.replace(my_regex,"x\$\&y");
or this:
var my_result = my_string.replace(my_regex,"x\\$&y");
or this:
var my_result = my_string.replace(my_regex,"x$&y");
or this:
var dollar = '$';
var amper = '&';
var my_result = my_string.replace(my_regex,"x" + dollar.charCodeAt(0) + amper.charCodeAt(0) + "y");
What else can I try?