除保留标点符号集以外,清除其他所有英文的标点符号(含空格)

5年以前  |  阅读数:419 次  |  编程语言:JavaScript 
//全部英文标点符号为:~`!@#$%^&*()-_+=[]{};:"',<.>/?
//参数excludePunctuation指需要保留的标点符号集,例如若传递的值为'_',即表示清除_以外的其他所有英文标点符号。
function clearPunctuation(str,excludePunctuation=null){
    let regexp = new RegExp(`[${getExcludePunctuation(excludePunctuation)}]`,'g');
    return str.replace(regexp,'');
}

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8