我有一个字符串,其中可能有特殊字符,我必须用连字符替换
var str="123.This is,, :ravi"
Run Code Online (Sandbox Code Playgroud)
上面的字符串应该像这样转换
var newstr="123-This-is-ravi";
Run Code Online (Sandbox Code Playgroud)
我一直在尝试这个
function remove(str){ str.replace(/\./g, "-"); } //replaces only dots
function remove(str){ str.replace(/ /g, "-"); } //replaces only spaces
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我这样做吗?我需要用连字符替换特殊字符.