对于我的生活,我无法弄清楚为什么这个正则表达式不起作用.它应该在给定的字符串中找到大写字母并给我计数.欢迎任何想法.
这是单元测试代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)