I have a string that is passed by parameter and I have to replace all occurrences of it in another string, ex:
function r(text, oldChar, newChar)
{
return text.replace(oldChar, newChar); // , "g")
}
The characters passed could be any character, including ^, |, $, [, ], (, )…
Is there a method to replace, for example, all ^ from the string I ^like^ potatoes with $?
1 Answer