我在网上学习Java正则表达式教程,对一个小程序感到困惑。
// String to be scanned to find the pattern.
String line = "This order was places for QT3000! OK?";
String pattern = "(.*)(\\d+)(.*)";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(line);
if (m.find( )) {
System.out.println("Found value: " + m.group(0) );
System.out.println("Found value: " + m.group(1) );
System.out.println("Found value: " + m.group(2) );
}
打印出来的结果是:
Found value: This order was places for QT3000! OK?
Found value: This order was places for QT300
Found value: 0
我不知道为什么 group(1) 获得上述值?为什么它在'QT3000'的最后一个零之前停止?
非常感谢你!