[−][src]Struct rec::Tokens
Stores the found capture groups.
Methods
impl<'_> Tokens<'_>
[src]
Methods from Deref<Target = Captures<'t>>
pub fn get(&self, i: usize) -> Option<Match<'t>>
[src]
Returns the match associated with the capture group at index i
. If
i
does not correspond to a capture group, or if the capture group
did not participate in the match, then None
is returned.
Examples
Get the text of the match with a default of an empty string if this group didn't participate in the match:
let re = Regex::new(r"[a-z]+(?:([0-9]+)|([A-Z]+))").unwrap(); let caps = re.captures("abc123").unwrap(); let text1 = caps.get(1).map_or("", |m| m.as_str()); let text2 = caps.get(2).map_or("", |m| m.as_str()); assert_eq!(text1, "123"); assert_eq!(text2, "");
pub fn name(&self, name: &str) -> Option<Match<'t>>
[src]
Returns the match for the capture group named name
. If name
isn't a
valid capture group or didn't match anything, then None
is returned.
pub fn iter(&'c self) -> SubCaptureMatches<'c, 't>
[src]
An iterator that yields all capturing matches in the order in which
they appear in the regex. If a particular capture group didn't
participate in the match, then None
is yielded for that capture.
The first match always corresponds to the overall match of the regex.
pub fn expand(&self, replacement: &str, dst: &mut String)
[src]
Expands all instances of $name
in replacement
to the corresponding
capture group name
, and writes them to the dst
buffer given.
name
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 name
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 $$
.
pub fn len(&self) -> usize
[src]
Returns the number of captured groups.
This is always at least 1
, since every regex has at least one capture
group that corresponds to the full match.
Trait Implementations
impl<'t> Deref for Tokens<'t>
[src]
type Target = Captures<'t>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl<'t> Debug for Tokens<'t>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,