Matcher.find finds the next subsequence, starting at a given index, which is compliant with the regex.
How can I make it so that it fails if the next character sequence is not compliant?
Ex:
String input = "123456text123";
Matcher mat1 = Pattern.compile("\\d+").matcher(input);
mat1.find();
System.out.println(mat1.group()); //123456
mat1.find(mat1.end());
System.out.println(mat1.group()); //123
I want to know if there’s a way to make the second find fail, since the next sequence does not match the mat1 pattern.
I want to be able to ‘compose’ matchers, in such a way that they MUST always be found in sequence.
Is it possible at all?
You can check that the previous
mat1.end()equals the nextmat1.start().