我真的想不出为什么这个正则表达式不起作用。它应该在给定的字符串中找到大写字母并给出计数。欢迎任何想法。
这是单元测试代码:
public class RegEx {
@Test
public void testCountTheNumberOfUpperCaseCharacters() {
String testStr = "abcdefghijkTYYtyyQ";
String regEx = "^[A-Z]+$";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(testStr);
System.out.printf("Found %d, of capital letters in %s%n", matcher.groupCount(), testStr);
}
}
groupCount
不会计算字符。答案总是相同的。 - Marko Topolnik+
(在你的2项列表中排名第1),以匹配你的代码。 - landru27