I want to understand how the below Java regular expression program worked. I am not able understand the second line in the output of the program
String line = "This order was placed for QT3000! OK?";
String pattern = "(.*)(\\d+)(.*)";
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) );
This produces an output like this
Found value: This order was placed for QT3000! OK?
Found value: This order was placed for QT300
Found value: 0
I understand that the pattern we are searching for in the string is a sequence that is a number (\d+) with anything before (.*) and after it (.*). Please correct me if I am wrong here.
I understood that m.group(0) returns the whole string. I didn't understand the second line of the output. Found value: This order was placed for QT300. What is happening here?
