Struct fancy_regex::Captures[][src]

pub struct Captures<'t> { /* fields omitted */ }
Expand description

A set of capture groups found for a regex.

Implementations

impl<'t> Captures<'t>[src]

pub fn get(&self, i: usize) -> Option<Match<'t>>[src]

Get the capture group by its index in the regex.

If there is no match for that group or the index does not correspond to a group, None is returned. The index 0 returns the whole match.

pub fn name(&self, name: &str) -> Option<Match<'t>>[src]

Returns the match for a named capture group. Returns None the capture group did not match or if there is no group with the given name.

pub fn expand(&self, replacement: &str, dst: &mut String)[src]

Expands all instances of $group in replacement to the corresponding capture group name, and writes them to the dst buffer given.

group may be an integer corresponding to the index of the capture group (counted by order of opening parenthesis where \0 is the entire match) or it can be a name (consisting of letters, digits or underscores) corresponding to a named capture group.

If group isn’t a valid capture group (whether the name doesn’t exist or isn’t a valid index), then it is replaced with the empty string.

The longest possible name is used. e.g., $1a looks up the capture group named 1a and not the capture group at index 1. To exert more precise control over the name, use braces, e.g., ${1}a.

To write a literal $, use $$.

For more control over expansion, see Expander.

pub fn iter<'c>(&'c self) -> SubCaptureMatches<'c, 't>

Notable traits for SubCaptureMatches<'c, 't>

impl<'c, 't> Iterator for SubCaptureMatches<'c, 't> type Item = Option<Match<'t>>;
[src]

Iterate over the captured groups in order in which they appeared in the regex. The first capture corresponds to the whole match.

pub fn len(&self) -> usize[src]

How many groups were captured. This is always at least 1 because group 0 returns the whole match.

Trait Implementations

impl<'t> Debug for Captures<'t>[src]

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

Formats the value using the given formatter. Read more

impl<'t, 'i> Index<&'i str> for Captures<'t>[src]

Copied from regex::Captures

Get a group by name.

't is the lifetime of the matched text and 'i is the lifetime of the group name (the index).

The text can’t outlive the Captures object if this method is used, because of how Index is defined (normally a[i] is part of a and can’t outlive it); to do that, use name instead.

Panics

If there is no group named by the given value.

type Output = str

The returned type after indexing.

fn index<'a>(&'a self, name: &'i str) -> &'a str[src]

Performs the indexing (container[index]) operation. Read more

impl<'t> Index<usize> for Captures<'t>[src]

Copied from regex::Captures

Get a group by index.

't is the lifetime of the matched text.

The text can’t outlive the Captures object if this method is used, because of how Index is defined (normally a[i] is part of a and can’t outlive it); to do that, use get() instead.

Panics

If there is no group at the given index.

type Output = str

The returned type after indexing.

fn index(&self, i: usize) -> &str[src]

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations

impl<'t> RefUnwindSafe for Captures<'t>

impl<'t> Send for Captures<'t>

impl<'t> Sync for Captures<'t>

impl<'t> Unpin for Captures<'t>

impl<'t> UnwindSafe for Captures<'t>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.