Is it possible to know if a stream/string contains an input that could match a regular expression.
For example
String input="AA";
Pattern pat=Pattern.compile("AAAAAB");
Matcher matcher=pat.matcher(input);
//<-- something here returning true ?
or
String input="BB";
Pattern pat=Pattern.compile("AAAAAB");
Matcher matcher=pat.matcher(input);
//<-- something here returning false ?
Thanks
Yes, Java provides a way to do that. First you have to call one of the standard methods to apply the regex, like
matches()orfind(). If that returnsfalse, you can use thehitEnd()method to find out if some longer string could have matched:output: