Match.groups
Group: Metadata
Documentation
Gets a vector containing the Text of all of the capturing groups in the pattern, replacing the value of groups that did not participate in the match with default
. This vector includes group 0, which contains the entire match.
Arguments
default
: The value to return for a given index when the group at that index did not participate in the match.
Examples
Get a vector of the text matched by all of the groups in this match,
replacing the value for groups that didn't match with "UNMATCHED".
import Standard.Examples
example_groups =
match = Examples.match
match.groups default="UNMATCHED"
Remarks
The Full Match
The group with index 0 is always the full match of the pattern.
Named Groups by Index
If the regex contained named groups, these may also be accessed by index based on their position in the pattern.
Note that it is possible for a group to "not participate in the match", for example with a disjunction. In the example below, the "(d)" group does not participate -- it neither matches nor fails.
"ab((c)|(d))".find "abc"
In this case, the group id for "(d)", which is 3, is a valid group id and
(Regex.lookup_group 3) will return 3. groups
will return the
default value for groups that do not participate.