java - Partial matching of Regular expression -
i have string incrementally built. while string being built, matched whole regular expression , when match found, task performed.
my requirement is: if in middle of string building process found there no way exact match found, string should reset , build process should re-initiated.
for example if regular expression "mada12gaskar"
, when char "3"
added existing string "mada1"
string should cleared , build process should start on again "mada13"
never match "mada12gaskar"
. possible through java regex api?
i think found possible solution problem.
look @ matcher#hitend()
method:
returns true if end of input hit search engine in last match operation performed matcher.
when method returns true, possible more input have changed result of last search.
now, match regexp against not-yet-fully-constructed string using matcher
(obtainable via pattern
instance) , @ results:
- if matched, have winner
- if didn't match, @
hitend()
:- if it's
true
, build more string , try again - if it's
false
, current string never matched, can drop , start over
- if it's
Comments
Post a Comment