我正在尝试从字符串中删除句号、逗号和空格。我很确定我必须使用这个来做到这一点:str.replace(<some Regex here>, "");
我对 Regex 不是很熟悉,我该怎么做?
最佳答案
使用这个正则表达式 /[.,\s]/g
var str = 'abc abc a, .aa ';
var regex = /[.,\s]/g;
var result = str.replace(regex, '');
document.write(result);
除了字符类 []
中的 ^-]\
之外,您不需要转义字符
Any character except ^-]\ add that character to the possible matches for the character class.
关于JavaScript 从字符串中删除句号、逗号和空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36817120/