views:

193

answers:

5

I need to make a replace of a plus sign in a javascript string. there might be multiple occurrence of the plus sign so I did this up until now:

myString= myString.replace(/+/g, "");#

This is however breaking up my javascript and causing glitches. How do you escape a '+' sign in a regular expression?

+1  A: 

You need to escape the + as its a meta char as follows:

myString= myString.replace(/\+/g, "");

Once escaped, + will be treated literally and not as a meta char.

codaddict
Thanks a lot, that was far simpler than I thought.
William Calleja
+2  A: 
myString = myString.replace(/\+/g, "");
Darin Dimitrov
Thanks a lot, that was far simpler than I thought.
William Calleja
+1  A: 

you should escape your + sign, \+

ghostdog74
A: 
myString.replace(/\+/g, "");
Marko Dumic
A: 

myString.replace(/+/g, ""); --> Giving javascript error for me. :(

KNL