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 left parenthesis that begins the group.
Group 0 represents the entire regular expression, so passing 0 to
start( ), end( ), or
group( ) is the same as calling the no-argument
version of the method.
public interface MatchResult {
// Public Instance Methods
int end( );
int end(int group);
String group( );
String group(int group);
int groupCount( );
int start( );
int start(int group);
}