1、替换一个字符
例如 把中间“,” 换成 “~”:
let text = "68530,68810"
方法一、text = text.replace(/,/," ~ ")
方法二、text = text.replace(","," ~ ")
2、替换所有字符(g代表所有)
text = text.replace(/,/g," ~ ")
3、替换带/或者\的特殊字符,例如</p>
此时需要用到转义字符/
text = text.replace(/</p>/g,"");
4、去掉字符串中的引号
let text = "68530,68810"
text = text.replace(/(^")|("$)/g, "")
5、去掉字符串中的中括号-[]
let text = [68530,68810]
text = text.replace(/[|]/g,'')