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.

Syntax

Tutorials

Existing support

Although Java's Matcher class supports partial matching, this useful feature is not widely known. A solution was mentioned in the Java forums, and 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).

In JavaStar

When you test a regular expression with JavaStar, if there are no matches, whether the input partially matches is displayed in the results section.

For example, you can see that 123 is a partial match for \d+\.\d+ by checking its results on JavaStar.