There is only way is replacing the string by regular expression. For example:
s = s.replace(/yourPaternString/g, 'yourNewValue');However, the patern string may not work when it contains metacharacter of regex, such as . $ ^ { [ ( | ) * + ? \. We need to escape these characters by following code:
patern = patern.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); text = text.replace(new RegExp(patern, 'g'), 'yourNewValue');