1. Hide the middle 4 digits of the mobile phone number
var phone = "18200002111";
phone.replace(/^(\d{3})\d+(\d{4})$/."$1 * * * * $2");
Copy the code
2, id card hide the middle number
var idcard = '530026222211032101';
idcard.replace(/^(\d{6})\d+(\d{4})$/."$1 * * * * * * $2");
Copy the code
3. Display only the last digit of the name
var name = 'Joe';
name.replace(/. (? =) /g.The '*');
Copy the code
4. Display the first word of the name
let name ="Fifty"
let newname = name.replace(/ (? < =.) ./g.The '*');
Copy the code