String input = "ABCD1234BCDE"; String mode = "BCD"; Pattern pattern = Pattern.compile(mode); int count = 0; Matcher matcher = pattern.matcher(input); while(matcher.find()) { count++; }
匹配到两次就会退出while循环
注意不能这么写,这么写永远退不出来
while(pattern.matcher(input).find()) { count++; }