var data = "3265986532146598"; console.log(data.replace(/\s/g,'').replace(/(\d{4})\d+(\d{4})$/, "**** **** **** $2")) //最后输出为:**** **** **** 6598下面的正则,显示前4位和后4位,中间的全部用星号显示(1234 **** **** 1234):
var data = "3265986532146598"; console.log(data.replace(/\s/g,'').replace(/(\d{4})\d+(\d{4})$/, "$1 **** **** $2")) //最后输出为:3265 **** **** 6598