Una expresión regular de Java sobre cómo encontrar una cadena de dígitos
Estaba aprendiendo un tutorial de expresión regular de Java en línea y me confundí con un pequeño programa.
// 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) );
}
Y los resultados impresos son:
Found value: This order was places for QT3000! OK?
Found value: This order was places for QT300
Found value: 0
¿No tengo idea de por qué el grupo (1) obtiene el valor anterior? ¿Por qué se detiene antes del último cero de 'QT3000'?
¡Muchas gracias!