Mo. Mo. - 1 month ago 9
Javascript Question

Replace forward slash "/ " character in JavaScript string?

I have this string:

var someString = "23/03/2012";


and want to replace all the "/" with "-".

I tried to do this:

someString.replace(///g, "-");


But it seems you cant have a forward slash in there.

Thanks

Answer

You need to escape your slash.

/\//g
Comments