Struct regress::Match

source ·
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: Range

The 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

source

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.

source

pub fn named_group(&self, name: &str) -> Option<Range>

Access a named group by name.

source

pub fn named_groups(&self) -> NamedGroups<'_>

Return an iterator over the named groups of a Match.

source

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.

source

pub fn start(&self) -> usize

Returns the starting byte offset of the match in the haystack.

source

pub fn end(&self) -> usize

Returns the ending byte offset of the match in the haystack.

source

pub fn groups(&self) -> Groups<'_>

Return an iterator over a Match. The first returned value is the total match, and subsequent values represent the capture groups.

Trait Implementations§

source§

impl Clone for Match

source§

fn clone(&self) -> Match

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Match

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Match

§

impl RefUnwindSafe for Match

§

impl Send for Match

§

impl Sync for Match

§

impl Unpin for Match

§

impl UnwindSafe for Match

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.