我有一小段代码,其中使用正则表达式从字符串中去掉标点、数字等。除了被去掉的字符串,我还得到了一个未定义的输出。有人能解释一下发生了什么吗?谢谢。
var regex = /[^a-zA-z\s\.]|_/gi;
function ripPunct(str) {
if ( str.match(regex) ) {
str = str.replace(regex).replace(/\s+/g, "");
}
return str;
}
console.log(ripPunct("*@£#__-=-=_+_devide-00000110490and586@multiply.edu"));