Package java.util.regex
Interface MatchResult
-
- All Known Implementing Classes:
Matcher
public interface MatchResultHolds the results of a successful match of aPatternagainst a given string. Typically this is an instance ofMatcher, but since that's a mutable class it's also possible to freeze its current state usingMatcher.toMatchResult().
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intend()Returns the index of the first character following the text that matched the whole regular expression.intend(int group)Returns the index of the first character following the text that matched a given group.Stringgroup()Returns the text that matched the whole regular expression.Stringgroup(int group)Returns the text that matched a given group of the regular expression.intgroupCount()Returns the number of groups in the results, which is always equal to the number of groups in the original regular expression.intstart()Returns the index of the first character of the text that matched the whole regular expression.intstart(int group)Returns the index of the first character of the text that matched a given group.
-
-
-
Method Detail
-
end
int end()
Returns the index of the first character following the text that matched the whole regular expression.
-
end
int end(int group)
Returns the index of the first character following the text that matched a given group. Seegroup()for an explanation of group indexes.
-
group
String group()
Returns the text that matched the whole regular expression.
-
group
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.
-
groupCount
int groupCount()
Returns the number of groups in the results, which is always equal to the number of groups in the original regular expression.
-
start
int start()
Returns the index of the first character of the text that matched the whole regular expression.
-
start
int start(int group)
Returns the index of the first character of the text that matched a given group. Seegroup()for an explanation of group indexes.
-
-