I am trying to replace all occurrences of a character in a string. This works when I use the RegExp() object to create the regular expression :
var str = "a-b-c-d";
var regex = new RegExp('\-','g');
str.replace(regex,'@');
So this works and I get "a@b@c@d".
What if I want to use an inline regular expression , say:
str.replace("/\-/g",'@')
it does not work. How do I do this without using RegExp();