In the following, I expect the second find() to succeed, but it does not. Why?
Matcher matcher =
Pattern.compile("\\s*asdf").matcher("apple banana cookie");
// returns false as expected
matcher.find();
// resets groups (that weren't being explicitly being used anyway), but not state.
matcher.usePattern(Pattern.compile("\\s*banana"));
// returns false, expected true.
System.out.println(matcher.find());
If the quantifier is removed from the first regex (becoming simply "asdf"), the second match succeeds. Looking at the Matcher object reveals some kind of group information is stored after the first unsuccessful find(), although I wouldn't have expected it. Find() is supposed to start either at the beginning (if no previous match) or at the index of the last successful match. UsePattern() is supposed to preserve the Matcher's position in the input, and discard group information (that, again, I wasn't using explicitly).
I'm missing something, but I don't know what. I'm suspecting I have to implement this with lookingAt() and updating the region (such as this example), but I don't know why this approach isn't working.