Name

MatchResult

Synopsis

This interface represents the results of a regular expression matching operation performed by a Matcher. Matcher implements this interface directly, and you can use the methods defined here to obtain the results of the most recent match performed by a Matcher. You can also save those most recent match results in a separate immutable MatchResult object by calling the toMatchResult( ) method of the Matcher.

The no-argument versions of the start( ) and end( ) method return the index of the first character that matched the pattern and the index of the last character that matched plus one (the index of the first character following the matched text), respectively. Some regular expressions can match the empty string. If this occurs, end( ) returns the same value as start( ). The no-argument version of group( ) returns the text that matched the pattern.

If the matched Pattern includes capturing subexpressions within parentheses, the other methods of this interface provide details about the text that matched each of those subexpressions. Pass a group number to start( ), end( ), or group( ) to obtain the start, end, or text that matched the specified group. groupCount( ) returns the number of subexpressions. Groups are numbered from 1, however, so legal group numbers run from 1 to the value returned by groupCount( ). Groups are ordered from left-to-right within the regular expression. When there are nested groups, their ordering is based on the position of the opening ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.