I'm trying to replace all the occurrences of a variable in a string using javascript.
This is not working.:
var id = "__1";
var re = new RegExp('/' + id + '/g');
var newHtml = oldHtml.replace( re, "__2");
This is only replacing the first occurrence of id:
var id = "__1";
var newHtml = oldHtml.replace( id,"__2");
What am I doing wrong here?
Thanks