t;a3b896cd3265ef123g456hh789987gg456ee")[7]); // System.out.println(p.split("a3b896cd3265ef123g456hh789987gg456ee")[8]); System.out.println("---------------"); System.out.println(Pattern.matches("\\d+", "2223")); // true System.out.println(Pattern.matches("\\d+", "2223aa")); // false System.out.println(Pattern.matches("\\d+", "22bb23")); // false Pattern p2 = Pattern.compile("\\d+"); Matcher m2 = p2.matcher("22bb23aa56ff78hh97gg65kk98pp88"); System.out.println(m2.pattern()); // \d+ System.out.println(m2.toString()); // java.util.regex.Matcher[pattern=\d+ region=0,6 lastmatch=] System.out.println(m2.regionStart()); // 0 System.out.println(m2.regionEnd()); // 18 System.out.println("=============+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.out.println(m2.matches()); // false // System.out.println(m2.start()); // System.out.println(m2.end()); // System.out.println(m2.group()); System.out.println(m2.find()); // true System.out.println(m2.start()); // 4 System.out.println(m2.end()); // 6 System.out.println(m2.group()); // 23 System.out.println(m2.find()); // true System.out.println(m2.start()); // 8 System.out.println(m2.end()); // 10 System.out.println(m2.group()); // 56 System.out.println(m2.find()); // true System.out.println(m2.start()); // 12 System.out.println(m2.end()); // 14 System.out.println(m2.group()); // 78 System.out.println(m2.matches()); // false 由于 开头部分匹配,指针将移动至开头,但不能获取结果 System.out.println(m2.lookingAt()); // true 由于 开头部分匹配,指针将移动至开头,但能获取结果 // System.out.println(m2.start()); // 0 // System.out.println(m2.end()); // 2 // System.out.println(m2.group()); // 22 S |