Why is this code not working as it should?
var temp = "@TEMP (A1)"
var text = "1st Oct @TEMP (A1)"
text = text.replace(new RegExp(temp, "gi"), "");
console.log(text); //I get same text even though I used replace instead of 1st Oct??
Can anybody explain what is going wrong here?
You need to quote the special characters of
tempwhich is being directly used as your regular expression. The(and)characters are grouping characters to the pattern, not actually matching ‘(‘ and ‘)’.