Incomplete match bug
Brought to you by:
samokhodkin
Hello,
In this the program:
public static void bug() {
Pattern pat1 = new Pattern("\\d\\d");
Pattern pat2 = new Pattern("\\d{2}");
System.out.println(pat1.startsWith("1")); //true
System.out.println(pat2.startsWith("1")); //false
}
The pattern \d\d is equivalent to the pattern \d{2} so why
the result is different ?
Seem that there are a bug here.
Sincerly,
Anthony
boulestreau@esiea.fr
Logged In: YES
user_id=908396
I think you misunderstand what Pattern.startsWith does. It
matches the target against the prefix of the pattern. "\d\d"
has a prefix that matches "1", namely "\d". "\d{2}" has no
prefix that could be separated from the rest. In this
particular regard, the two patterns are NOT equivalent. I'll
grant that this functionality is a bit confusing; I wouldn't
think that it's commonly used.