I would like to implement the following semantics:
while (EOF is not reached) {
    if (scanner.findWithinHorizon("^" + pattern1, 0)) {
        // do something
    } else if (scanner.findWithinHorizon("^" + pattern2, 0)) {
        // do something else
    } else {
        // report error
    }
}
Okay. The problem here is that Scanner doesn't match the new "head of the stream" with an anchored regex. For example, let's say we have a scanner new Scanner("11"). The first time we match it against the regex ^1 by calling scanner.findWithinHorizon("^1", 0) will return the matched string "1". However, the second call will return null, instead of the behavior I want, which will be returning "1" again because the new head of the stream is still '1' after consuming the first '1'.
Is there any way I can get the effect I want in Java?
Thanks in advance.
 
     
    