pub struct Match {
pub range: Range,
pub captures: Vec<Option<Range>>,
/* private fields */
}Expand description
A Match represents a portion of a string which was found to match a Regex.
Fields§
§range: RangeThe total range of the match. Note this may be empty, if the regex matched an empty string.
captures: Vec<Option<Range>>The list of captures. This has length equal to the number of capturing groups in the regex. For each capture, if the value is None, that group did not match (for example, it was in a not-taken branch of an alternation). If the value is Some, the group did match with the enclosed range.
Implementations§
Source§impl Match
impl Match
Sourcepub fn group(&self, idx: usize) -> Option<Range>
pub fn group(&self, idx: usize) -> Option<Range>
Access a group by index, using the convention of Python’s group() function. Index 0 is the total match, index 1 is the first capture group.
Sourcepub fn named_group(&self, name: &str) -> Option<Range>
pub fn named_group(&self, name: &str) -> Option<Range>
Access a named group by name.
Sourcepub fn named_groups(&self) -> NamedGroups<'_> ⓘ
pub fn named_groups(&self) -> NamedGroups<'_> ⓘ
Return an iterator over the named groups of a Match.
Sourcepub fn range(&self) -> Range
pub fn range(&self) -> Range
Returns the range over the starting and ending byte offsets of the match in the haystack.
This is a convenience function to work around the fact that Range does not support Copy.