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