Struct safe_regex::Groups [−][src]
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,
T: RefUnwindSafe,
impl<'d, T> Send for Groups<'d, T> where
T: Send,
T: Send,
impl<'d, T> Sync for Groups<'d, T> where
T: Sync,
T: Sync,
impl<'d, T> Unpin for Groups<'d, T> where
T: Unpin,
T: Unpin,
impl<'d, T> UnwindSafe for Groups<'d, T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut 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.
pub 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>,