验证码脱敏代码
private String encryptionCode(String content){
if (StringUtils.isEmpty(content)){
return content;
}
String res = null;
String reg = "(?<=[^\\d]{1})(\\d{4,6})(?=[^\\d]{1}|$)";
Pattern p = Pattern.compile(reg);
Matcher matcher = p.matcher(content);
while (matcher.find()) {
int start = matcher.start() + 1;
int end = matcher.end() - 1;
int len = end - start;
StringBuilder buffer = new StringBuilder();
for (int i = 0;i < len;i++){
buffer.append("*");
}
res = content.replaceAll(content.substring(start, end), buffer.toString());
}
return res;
}