Pattern p = Pattern.compile("1\\d");//1+一位数字 Matcher m = p.matcher("11::123::13"); while(m.find()){ System.out.println(m.group()); }这会印出: 11 12 13
另外,matches是判断整个字符串是否匹配。Java doc中是这样描述的:Attempts to match the entire input sequence against the pattern.If the match succeeds then more information can be obtained via the start, end, and group methods. Returns: true if, and only if, the entire input sequence matches this matcher's pattern
Matcher m = p.matcher("11::123::13");
while(m.find()){
System.out.println(m.group());
}这会印出:
11
12
13
Returns:
true if, and only if, the entire input sequence matches this matcher's pattern
matches("1\\d+")应该反回true的呀,为什么不是呢