手机号脱敏
String phone = "18888888888";
String result1 = phone.replaceAll("(\d{3})\d{4}(\d{4})", "$1****$2");
System.out.println("脱敏后的手机号:" + result1);
邮箱脱敏
String email = "mail@sniu.com";
String result = email.replaceAll("(^\w)[^@]*(@.*$)", "$1****$2");
System.out.println("脱敏后的邮箱:" + result);
身份证号脱敏
String idCard = "30010019990101123X";
String result = idCard.replaceAll("(?<=\w{3})\w(?=\w{4})", "*");
System.out.println("脱敏后的身份证号:" + result);
银行卡号脱敏
String bankCard = "1234561234567895678";
String result = bankCard.replaceAll("(\d{6})\d{9}(\d{4})", "$1****$2");
System.out.println("脱敏的银行卡号:" + result);
发表回复