I need to replace a html string with a dynamic value.This dynamic value(HTML encode) is to replace a pattern in the html string.
var htmlstring = \"
From Docs of replace, $&
Inserts the matched substring.
You can use the replace callback to get the $&
literal in the replaced string.
var htmlstring = "{NAME}";
var name = "$<Anonymous>" //Encoded form of "$";
var html = htmlstring.replace(/{NAME}/g, function(m) {
return name;
});
console.log(html);
document.write(html);