I'm new in studying JavaScript. I have a String
var str2= "1 dollor plus 2 dollor equal 3 dollor";
and I want convert to
$1 plus $2 equal $3
So I using function Replace() Like this:
str2 = str2.replace(/(\d+)\s/g, '\$$&");
str2 = str2.replace(/dollor/g, '');
But I get this str:
$& plus $& equal $&
I change my code like this:
str2 = str2.replace(/(\d+)\s/g, '\$'+"$&");
It doesn't work.I know my question maybe stupid.But I really don't know why the "\" cant escape "$". Forgive my poor English!