I've faced with strange behavior of java.util.regex.Matcher. Lets consider example:
Pattern p = Pattern.compile("\\d*");
String s = "a1b";
Matcher m = p.matcher(s);
while(m.find())
{
System.out.println(m.start()+" "+m.end());
}
It produces output:
0 0
1 2
2 2
3 3
I can understant all lines except last. Matcher creates extra group (3,3) out of string. But javadoc for method start() confirms:
start() Returns the start index of the previous match.
The same case for dot-star pattern:
Pattern p = Pattern.compile(".*");
String s = "a1b";
Matcher m = p.matcher(s);
while(m.find())
{
System.out.println(m.start()+" "+m.end());
}
Output:
0 3
3 3
But if specify line boundaries
Pattern p = Pattern.compile("^.*$");
The output will be "right":
0 3
Can someone explain me а reason of such behavior?