Intermediate 4-digit phone number Replace *

// replace the middle four mobile phone number

var STR = '15,912,341,234';
// A method
str.replace (/ (\ d {3 }) (\ d {4}) (\ d {3}) /, function ($ 0, $ 1, $ 2, $ 3) {
the console.log ($ +. 1 "****" + $. 3)
})
// method II
. str.replace (str.substr (3,4-), '*' REPEAT (. 4));
// method three
str. substr (0,3) + "*" . repeat (4) + str.substr (7)

Guess you like

Origin www.cnblogs.com/beizhi666/p/10939568.html