Java示例计数单词组 验证电话号码的Java示例 Java示例计算字符串中的一组单词 Java示例计数单词组 import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatcherGroupCountExample { public static void main(String args[]) { Pattern p = Pattern.compile("J(ava)"); String candidateString = "This is Java. This is a Java example."; Matcher matcher = p.matcher(candidateString); int numberOfGroups = matcher.groupCount(); System.out.println("numberOfGroups =" + numberOfGroups); } } 验证电话号码的Java示例 Java示例计算字符串中的一组单词