Replace forward slash "/ " character in JavaScript string?

Solution 1:

You need to escape your slash.

/\//g

Solution 2:

Try escaping the slash: someString.replace(/\//g, "-");

By the way - / is a (forward-)slash; \ is a backslash.

Solution 3:

First of all, that's a forward slash. And no, you can't have any in regexes unless you escape them. To escape them, put a backslash (\) in front of it.

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

Live example

Solution 4:

Escape it: someString.replace(/\//g, "-");