Replace forward slash “/ ” character in JavaScript string?

前端 未结 8 570
你的背包
你的背包 2020-12-02 15:35

I have this string:

var someString = \"23/03/2012\";

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

I tried to do this:

<         


        
8条回答
  •  旧巷少年郎
    2020-12-02 16:01

    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

提交回复
热议问题