JS正则去除字符串中的特殊字符

JS正则去除字符串中的特殊字符

需求:

去除特殊字符

demo(str) {
    
    
  //替换字符串中的所有特殊字符(包含空格)
  if(str){
    
    
    let Exp=/[\-\_\,\!\|\~\`\(\)\#\$\%\^\&\*\{\}\:\;\"\L\<\>\?]/g;
    string = string.replace(Exp,"");
  }
  return string
}

猜你喜欢

转载自blog.csdn.net/weixin_35773751/article/details/130525360