[−][src]Struct pcre2::bytes::Captures
Captures represents a group of captured byte strings for a single match.
The 0th capture always corresponds to the entire match. Each subsequent
index corresponds to the next capture group in the regex. If a capture
group is named, then the matched byte string is also available via the
name
method. (Note that the 0th capture is always unnamed and so must be
accessed with the get
method.)
Positions returned from a capture group are always byte indices.
's
is the lifetime of the matched subject string.
Methods
impl<'s> Captures<'s>
[src]
pub fn get(&self, i: usize) -> Option<Match<'s>>
[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:
use pcre2::bytes::Regex; let re = Regex::new(r"[a-z]+(?:([0-9]+)|([A-Z]+))")?; let caps = re.captures(b"abc123")?.unwrap(); let text1 = caps.get(1).map_or(&b""[..], |m| m.as_bytes()); let text2 = caps.get(2).map_or(&b""[..], |m| m.as_bytes()); assert_eq!(text1, &b"123"[..]); assert_eq!(text2, &b""[..]);
pub fn name(&self, name: &str) -> Option<Match<'s>>
[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 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<'s> Debug for Captures<'s>
[src]
impl<'s> Index<usize> for Captures<'s>
[src]
Get a group by index.
's
is the lifetime of the matched subject string.
The subject 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.
impl<'s, 'i> Index<&'i str> for Captures<'s>
[src]
Get a group by name.
's
is the lifetime of the matched subject string 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.
Auto Trait Implementations
impl<'s> Sync for Captures<'s>
impl<'s> Send for Captures<'s>
impl<'s> Unpin for Captures<'s>
impl<'s> RefUnwindSafe for Captures<'s>
impl<'s> UnwindSafe for Captures<'s>
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> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,