正则 去除字符串中的特殊字符
var
str=
"你的字符串~!#$%^&*()_+"
;
//你要清除的符号都放在方括号里,记得要用斜杠\转义一下,不然会出错
str = str.replace(/[要清除的符号]/g,
''
);
eg:
var url = 'https://gw.dushu.io/r/34440a483c1c' console.log(trim(url)) //结果:httpsgwdushuior34440a483c1c function trim(url) { url = url.replace(/\:/g,''); url = url.replace(/\//g,''); url = url.replace(/\./g,''); return url }