String email = "13072558368"; email = email.replaceAll("(\\d{3})\\d{6}(\\d{2})", "$1****$2"); System.out.println("email=" + email); email=130****68
从第三个开始,计算6个数字,其中计算的6个数字用*替换
String mobile = "15072332356"; // 表示数据是0到9的数据,总共有11位 String regexMobile = "^[0-9]{11}$"; String regexMobileSimple = "\\d{11}$"; boolean matches = mobile.matches(regexMobileSimple); if (matches) { System.out.println("符合手机号格式"); } else { System.out.println("不符合手机号格式"); }
// 非0开头,5到15位的数字 String qStringRegex = "[1-9][0-9]{4,14}";
// 开头以1开头,第二位是34578中任意一位,总共11位 String mobileRegex = "1[34578]\\d{9}";
标签:11,java,String,正则表达式,System,matches,简单,email,out From: https://www.cnblogs.com/q202105271618/p/16069807.html