Skip to content

Most visited

Recently visited

navigation
Added in API level 1

MatchResult

public interface MatchResult

java.util.regex.MatchResult
Known Indirect Subclasses


Holds the results of a successful match of a Pattern against a given string. Typically this is an instance of Matcher, but since that's a mutable class it's also possible to freeze its current state using toMatchResult().

Summary

Public methods

abstract int end()

Returns the index of the first character following the text that matched the whole regular expression.

abstract int end(int group)

Returns the index of the first character following the text that matched a given group.

abstract String group()

Returns the text that matched the whole regular expression.

abstract String group(int group)

Returns the text that matched a given group of the regular expression.

abstract int groupCount()

Returns the number of groups in the results, which is always equal to the number of groups in the original regular expression.

abstract int start()

Returns the index of the first character of the text that matched the whole regular expression.

abstract int start(int group)

Returns the index of the first character of the text that matched a given group.

Public methods

end

Added in API level 1
int end ()

Returns the index of the first character following the text that matched the whole regular expression.

Returns
int

end

Added in API level 1
int end (int group)

Returns the index of the first character following the text that matched a given group. See group() for an explanation of group indexes.

Parameters
group int
Returns
int

group

Added in API level 1
String group ()

Returns the text that matched the whole regular expression.

Returns
String

group

Added in API level 1
String group (int group)

Returns the text that matched a given group of the regular expression.

Explicit capturing groups in the pattern are numbered left to right in order of their opening parenthesis, starting at 1. The special group 0 represents the entire match (as if the entire pattern is surrounded by an implicit capturing group). For example, "a((b)c)" matching "abc" would give the following groups:

 0 "abc"
 1 "bc"
 2 "b"
 

An optional capturing group that failed to match as part of an overall successful match (for example, "a(b)?c" matching "ac") returns null. A capturing group that matched the empty string (for example, "a(b?)c" matching "ac") returns the empty string.

Parameters
group int
Returns
String

groupCount

Added in API level 1
int groupCount ()

Returns the number of groups in the results, which is always equal to the number of groups in the original regular expression.

Returns
int

start

Added in API level 1
int start ()

Returns the index of the first character of the text that matched the whole regular expression.

Returns
int

start

Added in API level 1
int start (int group)

Returns the index of the first character of the text that matched a given group. See group() for an explanation of group indexes.

Parameters
group int
Returns
int
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.