A stateful object tracking the result from the previous matching attempt.
The instances of this class are created by APIs on Regex. In addition to reporting whether it's a match, this class also provides break-down information such as the indexes of the matched region within the given input and the text for each captured group.
Once created, a Match object is associated with a Regex pattern. Methods such as next() will be called against that particular regex.
Parent Class
See Also
Type | Name | Signature |
---|---|---|
method | getEnd | public int getEnd() |
method | getGroup | public String getGroup(int) |
method | getGroups | public int getGroups() |
method | getStart | public int getStart() |
method | getText | public String getText() |
method | isMatched | public bool isMatched() |
method | next | public bool next() |
public int getEnd()
Get the 0-based end index of matched region.
Returns
public String getGroup(int index)
Get the text for each captured group.
The groups are captured in the order of left parenthesis. The group 0 is reserved for the entire matched region and thus is always available should the match succeed. Therefore suppose getGroups() returns N, this method can be called with any integer between 0 and N, inclusive. An example: Regex r = new Regex("(a?(b*)c?)(e+)");
Match m = r.matchAll("abee");
m.getGroups(); // 3
m.getGroup(0); // The entire matched region - equivalent to getText()
m.getGroup(1); // ab
m.getGroup(2); // b
m.getGroup(3); // ee
Parameters
Returns
Throws
public int getGroups()
Get the count of groups. Each ()
pair in a pattern forms one group. Note since a group may fall under an optional part of the regex, the value returned by this method is not necessarily equal to the total count of pairs in the pattern.
This method doesn't count group 0, defined as entire matched region.
Returns
public int getStart()
Get the 0-based start index of matched region.
Returns
public String getText()
Get the text of the matched region.
Returns
public bool isMatched()
Whether the previous attempt at matching, possibly driven by either next() or matchAll(string), was successful.
Returns
public bool next()
Try to find the next occurrence of the pattern.
If this Match object was returned from Regex.matchAll(string), calling this method will return false.
Returns