判断一段话中是否有电话号码,并将其进行隐藏:
public static String hidPhone(String string) { Pattern pattern = Pattern.compile("(?<!//d)(?:(?:1[34578]//d{9})|(?:861[34578]//d{9}))(?!//d)"); Matcher matcher = pattern.matcher(string); StringBuffer bf = new StringBuffer(64); while (matcher.find()) { // bf.append(matcher.group()).append(","); // System.out.println(matcher.group()); string = string.replace(matcher.group(), matcher.group().substring(0,3)+"********"); } // int len = bf.length(); // if (len > 0) { // bf.deleteCharAt(len - 1); // } // System.out.println(bf.toString()); return string; }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/10251.html