Mo. Mo. - 1 year ago 116
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 Source

You need to escape your slash.

/\//g