The code is given below:
import java.util.regex.*;
public class RegEx {
public static void main(String[] args) {
Pattern p = Pattern.compile("\\d*");
Matcher m = p.matcher("ab56ef");
System.out.println("Pattern is " + m.pattern());
while (m.find()) {
System.out.print("index: " + m.start() + " " + m.group());
}
}
}
The result is:
index: 0 index: 1 index: 2 56 index: 4 index: 5 index: 6
Since "ab34ef" length is 6, the string's highest index is 5.
Why is there a match at index 6? Thank you in advance!