1.手机号隐藏中间4位
代码:
let str = 15945253565;
var reg = /^(\d{3})\d{4}(\d{4})$/;
let a = str.replace(reg, "$1****$2");
console.log(a)
2.数字3位数隔开
let wordCount = 130320;
var str = wordCount.toString();
var reg = str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
str = str.replace(reg, "$1,");