更新时间:2023-01-22 19:20:52
您应该使用单个正则表达式的字符串替换功能。
假设特殊字符,你的意思是任何不是字母,这是一个解决方案:
You should use the string replace function, with a single regex. Assuming by special characters, you mean anything that's not letter, here is a solution:
var str = "abc's test#s";
alert(str.replace(/[^a-zA-Z ]/g, ""));