MatchResult
Stay organized with collections
Save and categorize content based on your preferences.
Known Indirect Subclasses
Matcher |
J2ObjC modified: Synchronizations are removed because they were added in the Android sources
to safeguard against hard-to-debug crashes from incorrect concurrent use of this class. |
|
The result of a match operation.
This interface contains query methods used to determine the
results of a match against a regular expression. The match boundaries,
groups and group boundaries can be seen but not modified through
a MatchResult
.
Public Method Summary
abstract
int
|
end(int group)
Returns the offset after the last character of the subsequence
captured by the given group during this match.
|
abstract
int
|
end()
Returns the offset after the last character matched.
|
abstract
String
|
group(int group)
Returns the input subsequence captured by the given group during the
previous match operation.
|
abstract
String
|
group()
Returns the input subsequence matched by the previous match.
|
abstract
int
|
groupCount()
Returns the number of capturing groups in this match result's pattern.
|
abstract
int
|
start()
Returns the start index of the match.
|
abstract
int
|
start(int group)
Returns the start index of the subsequence captured by the given group
during this match.
|
Public Methods
public
abstract
int
end
(int group)
Returns the offset after the last character of the subsequence
captured by the given group during this match.
Capturing groups are indexed from left
to right, starting at one. Group zero denotes the entire pattern, so
the expression m.end(0) is equivalent to
m.end().
Parameters
group |
The index of a capturing group in this matcher's pattern |
Returns
- The offset after the last character captured by the group,
or -1 if the match was successful
but the group itself did not match anything
public
abstract
int
end
()
Returns the offset after the last character matched.
Returns
- The offset after the last character matched
public
abstract
String
group
(int group)
Returns the input subsequence captured by the given group during the
previous match operation.
For a matcher m, input sequence s, and group index
g, the expressions m.group(g) and
s.substring(m.start(g), m.end(g))
are equivalent.
Capturing groups are indexed from left
to right, starting at one. Group zero denotes the entire pattern, so
the expression m.group(0) is equivalent to m.group().
If the match was successful but the group specified failed to match
any part of the input sequence, then null is returned. Note
that some groups, for example (a*), match the empty string.
This method will return the empty string when such a group successfully
matches the empty string in the input.
Parameters
group |
The index of a capturing group in this matcher's pattern |
Returns
- The (possibly empty) subsequence captured by the group
during the previous match, or null if the group
failed to match part of the input
public
abstract
String
group
()
Returns the input subsequence matched by the previous match.
For a matcher m with input sequence s,
the expressions m.group() and
s.substring(m.start(), m.end())
are equivalent.
Note that some patterns, for example a*, match the empty
string. This method will return the empty string when the pattern
successfully matches the empty string in the input.
Returns
- The (possibly empty) subsequence matched by the previous match,
in string form
public
abstract
int
groupCount
()
Returns the number of capturing groups in this match result's pattern.
Group zero denotes the entire pattern by convention. It is not
included in this count.
Any non-negative integer smaller than or equal to the value
returned by this method is guaranteed to be a valid group index for
this matcher.
Returns
- The number of capturing groups in this matcher's pattern
public
abstract
int
start
()
Returns the start index of the match.
Returns
- The index of the first character matched
public
abstract
int
start
(int group)
Returns the start index of the subsequence captured by the given group
during this match.
Capturing groups are indexed from left
to right, starting at one. Group zero denotes the entire pattern, so
the expression m.start(0) is equivalent to
m.start().
Parameters
group |
The index of a capturing group in this matcher's pattern |
Returns
- The index of the first character captured by the group,
or -1 if the match was successful but the group
itself did not match anything
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eMatchResult\u003c/code\u003e is an interface that provides methods to query the results of a regular expression match operation.\u003c/p\u003e\n"],["\u003cp\u003eIt allows access to match boundaries, groups, and group boundaries but does not permit modification of the match result.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eMatchResult\u003c/code\u003e includes methods like \u003ccode\u003estart()\u003c/code\u003e, \u003ccode\u003eend()\u003c/code\u003e, \u003ccode\u003egroup()\u003c/code\u003e, and \u003ccode\u003egroupCount()\u003c/code\u003e to retrieve match information.\u003c/p\u003e\n"],["\u003cp\u003eImplementations like \u003ccode\u003eMatcher\u003c/code\u003e use \u003ccode\u003eMatchResult\u003c/code\u003e to represent the outcome of regex matching.\u003c/p\u003e\n"],["\u003cp\u003eJ2ObjC has modified the \u003ccode\u003eMatcher\u003c/code\u003e implementation to remove synchronizations for better performance.\u003c/p\u003e\n"]]],["`MatchResult` is an interface for determining the results of a regular expression match. Key actions include: `start(int group)` and `end(int group)`, which return the start and end indices of captured subsequences, respectively, and `group(int group)`, which returns the captured subsequence. `group()` returns the entire matched subsequence, `start()` and `end()` return the start and end of the entire match. `groupCount()` provides the number of capturing groups in the pattern. These actions enable examination of match boundaries, groups, and group boundaries.\n"],null,["# MatchResult\n\npublic interface **MatchResult** \n\n|---|---|---|\n| Known Indirect Subclasses [Matcher](../../../../reference/java/util/regex/Matcher.html) |---------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Matcher](../../../../reference/java/util/regex/Matcher.html) | J2ObjC modified: Synchronizations are removed because they were added in the Android sources to safeguard against hard-to-debug crashes from incorrect concurrent use of this class. | |||\n\nThe result of a match operation.\n\nThis interface contains query methods used to determine the\nresults of a match against a regular expression. The match boundaries,\ngroups and group boundaries can be seen but not modified through\na `MatchResult`. \n\n##### See Also\n\n- [Matcher](../../../../reference/java/util/regex/Matcher.html) \n\n### Public Method Summary\n\n|----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract int | [end](../../../../reference/java/util/regex/MatchResult.html#end(int))(int group) Returns the offset after the last character of the subsequence captured by the given group during this match. |\n| abstract int | [end](../../../../reference/java/util/regex/MatchResult.html#end())() Returns the offset after the last character matched. |\n| abstract [String](../../../../reference/java/lang/String.html) | [group](../../../../reference/java/util/regex/MatchResult.html#group(int))(int group) Returns the input subsequence captured by the given group during the previous match operation. |\n| abstract [String](../../../../reference/java/lang/String.html) | [group](../../../../reference/java/util/regex/MatchResult.html#group())() Returns the input subsequence matched by the previous match. |\n| abstract int | [groupCount](../../../../reference/java/util/regex/MatchResult.html#groupCount())() Returns the number of capturing groups in this match result's pattern. |\n| abstract int | [start](../../../../reference/java/util/regex/MatchResult.html#start())() Returns the start index of the match. |\n| abstract int | [start](../../../../reference/java/util/regex/MatchResult.html#start(int))(int group) Returns the start index of the subsequence captured by the given group during this match. |\n\nPublic Methods\n--------------\n\n#### public abstract int\n**end**\n(int group)\n\nReturns the offset after the last character of the subsequence\ncaptured by the given group during this match.\n\n[Capturing groups](/j2objc/javadoc/jre/reference/java/util/regex/Pattern#cg) are indexed from left\nto right, starting at one. Group zero denotes the entire pattern, so\nthe expression *m.* end(0) is equivalent to\n*m.* end().\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| group | The index of a capturing group in this matcher's pattern |\n|-------|----------------------------------------------------------|\n\n##### Returns\n\n- The offset after the last character captured by the group, or -1 if the match was successful but the group itself did not match anything \n\n##### Throws\n\n| [IllegalStateException](../../../../reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |\n| [IndexOutOfBoundsException](../../../../reference/java/lang/IndexOutOfBoundsException.html) | If there is no capturing group in the pattern with the given index |\n|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|\n\n#### public abstract int\n**end**\n()\n\nReturns the offset after the last character matched. \n\n##### Returns\n\n- The offset after the last character matched \n\n##### Throws\n\n| [IllegalStateException](../../../../reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |\n|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|\n\n#### public abstract [String](../../../../reference/java/lang/String.html)\n**group**\n(int group)\n\nReturns the input subsequence captured by the given group during the\nprevious match operation.\n\nFor a matcher *m* , input sequence *s* , and group index\n*g* , the expressions *m.* group(*g* ) and\n*s.* substring(*m.* start(*g* ), *m.* end(*g* ))\nare equivalent.\n\n[Capturing groups](/j2objc/javadoc/jre/reference/java/util/regex/Pattern#cg) are indexed from left\nto right, starting at one. Group zero denotes the entire pattern, so\nthe expression m.group(0) is equivalent to m.group().\n\nIf the match was successful but the group specified failed to match\nany part of the input sequence, then null is returned. Note\nthat some groups, for example (a\\*), match the empty string.\nThis method will return the empty string when such a group successfully\nmatches the empty string in the input.\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| group | The index of a capturing group in this matcher's pattern |\n|-------|----------------------------------------------------------|\n\n##### Returns\n\n- The (possibly empty) subsequence captured by the group during the previous match, or null if the group failed to match part of the input \n\n##### Throws\n\n| [IllegalStateException](../../../../reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |\n| [IndexOutOfBoundsException](../../../../reference/java/lang/IndexOutOfBoundsException.html) | If there is no capturing group in the pattern with the given index |\n|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|\n\n#### public abstract [String](../../../../reference/java/lang/String.html)\n**group**\n()\n\nReturns the input subsequence matched by the previous match.\n\nFor a matcher *m* with input sequence *s* ,\nthe expressions *m.* group() and\n*s.* substring(*m.* start(), *m.* end())\nare equivalent.\n\nNote that some patterns, for example a\\*, match the empty\nstring. This method will return the empty string when the pattern\nsuccessfully matches the empty string in the input.\n\n\u003cbr /\u003e\n\n##### Returns\n\n- The (possibly empty) subsequence matched by the previous match, in string form \n\n##### Throws\n\n| [IllegalStateException](../../../../reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |\n|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|\n\n#### public abstract int\n**groupCount**\n()\n\nReturns the number of capturing groups in this match result's pattern.\n\nGroup zero denotes the entire pattern by convention. It is not\nincluded in this count.\n\nAny non-negative integer smaller than or equal to the value\nreturned by this method is guaranteed to be a valid group index for\nthis matcher.\n\n\u003cbr /\u003e\n\n##### Returns\n\n- The number of capturing groups in this matcher's pattern \n\n#### public abstract int\n**start**\n()\n\nReturns the start index of the match. \n\n##### Returns\n\n- The index of the first character matched \n\n##### Throws\n\n| [IllegalStateException](../../../../reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |\n|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|\n\n#### public abstract int\n**start**\n(int group)\n\nReturns the start index of the subsequence captured by the given group\nduring this match.\n\n[Capturing groups](/j2objc/javadoc/jre/reference/java/util/regex/Pattern#cg) are indexed from left\nto right, starting at one. Group zero denotes the entire pattern, so\nthe expression *m.* start(0) is equivalent to\n*m.* start().\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| group | The index of a capturing group in this matcher's pattern |\n|-------|----------------------------------------------------------|\n\n##### Returns\n\n- The index of the first character captured by the group, or -1 if the match was successful but the group itself did not match anything \n\n##### Throws\n\n| [IllegalStateException](../../../../reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |\n| [IndexOutOfBoundsException](../../../../reference/java/lang/IndexOutOfBoundsException.html) | If there is no capturing group in the pattern with the given index |\n|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|"]]