startWith & named backreferences
Brought to you by:
samokhodkin
I'm using startWith combined with Named backreferences.
And if I cut the reference,
the startWith method returns false even when it should
be true.
Here is the code:
Pattern p = new Pattern( "({ones}1*)a*{\ones}" );
String testCase = "11a1";
System.err.println( testCase + " startsWith() for the
pattern:" + p.startsWith(testCase) );
but, if I change the testCase to "11a11" or "11a" it
works fine.
Logged In: YES
user_id=908396
I think you misunderstand what Pattern.startsWith does.
"11a1" is not a prefix of p, but both "11a" and "11a11" are.
The former matches "({ones}1*)a*", and the latter matches
the whole of p. That's because the "\ones" backreference
matches "11", not "1". (Also see my comment to bug 667201
and the other one you files.)