Partial match
A partial match is defined to be a prefix of some valid match. For example,
123
is a partial match for the regex \d+\.\d+
, since appending, for example, .4
yields the match 123.4
.
Also note that 123.4
is also a partial match,
since appending the empty string will yield a valid match. In other words, a
match is also a partial match, by definition.
Existing support
Although Java's Matcher class supports partial matching, this useful feature is not widely known. To simplify testing for partial matches the isPartialMatch method has been included in RegExPlus.
Usage
A common usage of partial matching is as an "early detection" of invalid input entered into a textfield.
Instead of waiting to validate all the fields after pressing a "submit"
button, notification can be provided immediately when it is known that
additional characters cannot yield a valid match (that is, when the
isPartialMatch
method returns false
).