I have a String that is incrementally built. While the string being built, it is matched as a whole by a regular expression and when a match is found, a certain task is performed.
My requirement is: If in the middle of the string building process it is found that there is no way an exact match will be found, then the string should be reset and the build process should be re-initiated.
For example if a regular expression is "mada12gaskar"
and when a char "3"
is added to an existing string "mada1"
the string should be cleared and the build process should start over again as "mada13"
will never match with "mada12gaskar"
. Is this possible through Java regex API?