Module regex_automata::util::captures
source · Expand description
Provides types for dealing with capturing groups.
Capturing groups refer to sub-patterns of regexes that some regex engines can
report matching offsets for. For example, matching [a-z]([0-9]+)
against
a789
would give a789
as the overall match (for the implicit capturing group
at index 0
) and 789
as the match for the capturing group ([0-9]+)
(an
explicit capturing group at index 1
).
Not all regex engines can report match offsets for capturing groups. Indeed, to a first approximation, regex engines that can report capturing group offsets tend to be quite a bit slower than regex engines that can’t. This is because tracking capturing groups at search time usually requires more “power” that in turn adds overhead.
Other regex implementations might call capturing groups “submatches.”
§Overview
The main types in this module are:
Captures
records the capturing group offsets found during a search. It provides convenience routines for looking up capturing group offsets by either index or name.GroupInfo
records the mapping between capturing groups and “slots,” where the latter are how capturing groups are recorded during a regex search. This also keeps a mapping from capturing group name to index, and capture group index to name. AGroupInfo
is used byCaptures
internally to provide a convenient API. It is unlikely that you’ll use aGroupInfo
directly, but for example, if you’ve compiled an Thompson NFA, then you can usethompson::NFA::group_info
to get its underlyingGroupInfo
.
Structs§
- The span offsets of capturing groups after a match has been found.
- A little helper type to provide a nice map-like debug representation for our capturing group spans.
- An iterator over all capturing groups in a
Captures
value. - Represents information about capturing groups in a compiled regex.
- An iterator over capturing groups and their names for a
GroupInfo
. - An error that may occur when building a
GroupInfo
. - The inner guts of
GroupInfo
. This type only exists so that it can be wrapped in anArc
to makeGroupInfo
reference counted. - An iterator over capturing groups and their names for a specific pattern.
Enums§
- The kind of error that occurs when building a
GroupInfo
fails.
Type Aliases§
- A map from capture group name to its corresponding capture group index.