脱敏规则
数字个位数不显示,2位及以上显示最后1位数字,有中文字全部显示
如:22弄22号20层2003室→*2弄*2号*0层**3室
22弄1号20层2003室→*2弄*号*0层**3室
1弄1号1层1室→*弄*号*层*室
/**
* 脱敏地址字符串中的数字* @param address
* @return
*/
public static String addressTM(String address) {
if(address == null) {
return "";
}
char[] aa = address.toCharArray();
String newAddr = "";
String temp = "";
for(int a = aa.length - 1; a >= 0; a--) {
if((int)aa[a] >= '0' && (int)aa[a] <= '9') {
temp = aa[a] + temp;
} else {
if(temp.length() > 0) {
int l = 2;
newAddr = temp.substring((temp.length() < l ? l : temp.length()) - 1, temp.length()) + newAddr;
if(temp.length() - 1<1){
newAddr = "*" + newAddr;
}else{
for(int b = 0; b < temp.length() - 1; b++) {
newAddr = "*" + newAddr;
}
}
}
temp = "";
newAddr = aa[a] + newAddr;
}
}
//武胜路333号1层
Pattern p = Pattern.compile(".*\\d+.*");
Matcher m = p.matcher(temp);
if(m.matches()){
if(temp.length()>1){
newAddr="*"+temp.substring(temp.length()-1,temp.length())+newAddr;
for (int i = 0; i < temp.length()-2; i++) {
newAddr="*"+newAddr;
}
}else{
newAddr="*"+newAddr;
}
}
return newAddr;
}