Skip to main content

Match.span

spangroupdefault

Group: Metadata

Documentation

Gets the grapheme span matched by the group with the provided identifier, or a default value if the group did not participate in the match. If no such group exists for the provided identifier, a No_Such_Group is returned.

Arguments

  • group: The integer index or name of that group.

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.

What is a Character?

A character is defined as an Extended Grapheme Cluster, see Unicode Standard Annex 29. This is the smallest unit that still has semantic meaning in most text-processing applications.

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. If the caller tries to get group 3, Match.span will return the default value.