public static void main(String[] args) { String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[$@$!%*?^&~#()-+=;,.{}<>/?])[A-Za-z\\d**$@$**!%*?&]{12,}$"; // 替换为你的正则表达式 String input = "gzh12345678GZH@"; // 替换为你的待验证的字符串 Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(input); if (matcher.matches()) { System.out.println("字符串符合正则表达式"); } else { System.out.println("字符串不符合正则表达式"); } }
标签:String,正则表达式,matcher,System,Pattern,字符串 From: https://www.cnblogs.com/lovleo/p/17928168.html