Trait RegexSplit

Source
pub trait RegexSplit {
    // Required methods
    fn split_inclusive<'r, 't>(
        &'r self,
        text: &'t [u8],
    ) -> SplitInclusive<'r, 't> ;
    fn split_inclusive_left<'r, 't>(
        &'r self,
        text: &'t [u8],
    ) -> SplitInclusiveLeft<'r, 't> ;
}

Required Methods§

Source

fn split_inclusive<'r, 't>(&'r self, text: &'t [u8]) -> SplitInclusive<'r, 't>

Source

fn split_inclusive_left<'r, 't>( &'r self, text: &'t [u8], ) -> SplitInclusiveLeft<'r, 't>

Implementations on Foreign Types§

Source§

impl RegexSplit for Regex

Source§

fn split_inclusive<'r, 't>(&'r self, text: &'t [u8]) -> SplitInclusive<'r, 't>

Returns an iterator of substrings of text separated by a match of the regular expression. Differs from the iterator produced by split in that split_inclusive leaves the matched part as the terminator of the substring.

This method will not copy the text given.

§Example
let re = Regex::new(r"\r?\n").unwrap();
let text = b"Mary had a little lamb\nlittle lamb\r\nlittle lamb.";
let v: Vec<&[u8]> = re.split_inclusive(text).collect();
assert_eq!(v, [
    &b"Mary had a little lamb\n"[..],
    &b"little lamb\r\n"[..],
    &b"little lamb."[..]
]);
Source§

fn split_inclusive_left<'r, 't>( &'r self, text: &'t [u8], ) -> SplitInclusiveLeft<'r, 't>

Returns an iterator of substrings of text separated by a match of the regular expression. Differs from the iterator produced by split in that split_inclusive leaves the matched part as the terminator of the substring.

This method will not copy the text given.

§Example
let re = Regex::new(r"\r?\n").unwrap();
let text = b"Mary had a little lamb\nlittle lamb\r\nlittle lamb.";
let v: Vec<&[u8]> = re.split_inclusive_left(text).collect();
assert_eq!(v, [
    &b"Mary had a little lamb"[..],
    &b"\nlittle lamb"[..],
    &b"\r\nlittle lamb."[..]
]);

Implementors§