Struct safe_regex::Groups[][src]

pub struct Groups<'d, T: AsRef<[Range<u32>]>> { /* fields omitted */ }

Groups captured by a regular expression.

Implementations

impl<'d, T: AsRef<[Range<u32>]>> Groups<'d, T>[src]

pub fn new(ranges: T, data: &'d [u8]) -> Self[src]

Creates a new struct.

data is the byte string the regular expression matched against.

ranges is an array of ranges which are the regions inside data that matched capturing groups.

pub fn group_range(&self, n: usize) -> Option<Range<usize>>[src]

Get the range of capturing group number n. To find the n value for a particular group in a regex, count the number of open parenthesis ( symbols that appear before the group.

Note: Group 0 is the first group. It is NOT the matching portion of the string.

Returns None if the group did not match any portion of the string.

Panics if the regular expression does not have a capturing group n.

Examples

use safe_regex::{regex, Matcher};
let re: Matcher<_> = regex!(br"(a)(b)");
let groups = re.match_all(b"ab").unwrap();
assert_eq!(0..1, groups.group_range(0).unwrap());
assert_eq!(1..2, groups.group_range(1).unwrap());
// groups.group_range(2); // panics
use safe_regex::{regex, Matcher};
let re: Matcher<_> = regex!(br"(a)|(b)");
let groups = re.match_all(b"b").unwrap();
assert_eq!(None, groups.group_range(0));
assert_eq!(Some(0..1), groups.group_range(1));

pub fn group(&self, n: usize) -> Option<&[u8]>[src]

Gets the slice matched by capturing group number n.

To find the n value for a particular group in a regex, count the number of open parenthesis ( symbols that appear before the group.

Note: Group 0 is the first group. It is NOT the matching portion of the string.

Returns None if the group did not match any portion of the string.

Panics if the regular expression does not have a capturing group n.

Examples

use safe_regex::{regex, Matcher};
let re: Matcher<_> = regex!(br"(a)(b)");
let groups = re.match_all(b"ab").unwrap();
assert_eq!(b"a", groups.group(0).unwrap());
assert_eq!(b"b", groups.group(1).unwrap());
// groups.group(2); // panics
use safe_regex::{regex, Matcher};
let re: Matcher<_> = regex!(br"(a)|(b)");
let groups = re.match_all(b"b").unwrap();
assert_eq!(None, groups.group(0));
assert_eq!(b"b", groups.group(1).unwrap());

Trait Implementations

impl<'d, T: Clone + AsRef<[Range<u32>]>> Clone for Groups<'d, T>[src]

impl<'d, T: Debug + AsRef<[Range<u32>]>> Debug for Groups<'d, T>[src]

impl<'d, T: PartialEq + AsRef<[Range<u32>]>> PartialEq<Groups<'d, T>> for Groups<'d, T>[src]

impl<'d, T: AsRef<[Range<u32>]>> StructuralPartialEq for Groups<'d, T>[src]

Auto Trait Implementations

impl<'d, T> RefUnwindSafe for Groups<'d, T> where
    T: RefUnwindSafe

impl<'d, T> Send for Groups<'d, T> where
    T: Send

impl<'d, T> Sync for Groups<'d, T> where
    T: Sync

impl<'d, T> Unpin for Groups<'d, T> where
    T: Unpin

impl<'d, T> UnwindSafe for Groups<'d, T> where
    T: UnwindSafe

Blanket Implementations

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

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

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

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.

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.