public void matcher(String text) {
long c1 = 0;
long c2 = 0;
if (StringUtils.isBlank(text)) {
System.out.println("汉字数量:0" + "\n" + "单词数量:0");
return;
}
text = text.replace("\r", " ").replace("\n", " ");
while (matcher.find()) {
if (StringUtils.isNotBlank(Pattern.compile("([a-zA-z]*)").matcher(text).group())) {
c1++;
}
}
char c[] = text.toCharArray();
for (int i = 0; i < c.length; i++) {
if (Pattern.compile("[\u4e00-\u9fa5]").matcher(String.valueOf(c[i])).matches()) {
c2++;
}
}
System.out.println("汉字数量:" + c2 + "\n" + "单词数量:" + c1);
}