I am trying to write a function which replaces certain words with abbreviations. For example I have the string:
str="Calculate $2\\cdot 2$"
in which I want to replace
"\\cdot"
with
"*"
My code looks like this:
str = str.replace(RegExp("\\cdot",'g'),"*");
And the result is
str = "Calculate $2\\cdot 2$"
And I need to use the RegExp function because I have a whole list of words which I want to replace with abbreviations. I know that
str = str.replace(/\\cdot/g),"*");
works. But I don't understand why RegExp doesn't.