Reputation: 483
I need to take all plus symbols from a variable and replace them with spaces. I have tried:
someVariable = "0+123+45+6";
someVariable.replace(/+/g, ' ');
But this doesn't work... what would be the correct syntax for this situation?
Upvotes: 1
Views: 154
Reputation: 40872
the +
is a special char (one or more), so you need to escape it.
should be /\+/g
EDIT the regular expression does not modify the string object itself. but returns the result.
someVariable = "0+123+45+6";
someVariable = someVariable.replace(/\+/g, ' ');
Upvotes: 3