Currently I am trying to make a function in JavaScript that takes three arguments;
1. Template String
2. Word To Replace
3. Word To Replace With
Here's what I tried:
function replaceAll(templateString, wordToReplace, replaceWith)
{
var regex = new RegExp("/" + wordToReplace + "/","g");
return templateString.replace(regex, replaceWith);
}
console.log(replaceAll('My name is {{MyName}}', '{{MyName}}', 'Ahmed'));
But it's still giving me the templateString
back. Without replacing.
This is what I got back: My name is {{MyName}}