Trait RegexSplit

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

Required Methods§

Source

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

Source

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

Implementations on Foreign Types§

Source§

impl RegexSplit for Regex

Source§

fn split_inclusive<'r, 't>(&'r self, text: &'t str) -> 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 = "Mary had a little lamb\nlittle lamb\r\nlittle lamb.";
let v: Vec<&str> = re.split_inclusive(text).collect();
assert_eq!(v, [
    "Mary had a little lamb\n",
    "little lamb\r\n",
    "little lamb.",
]);
Source§

fn split_inclusive_left<'r, 't>( &'r self, text: &'t str, ) -> 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 = "Mary had a little lamb\nlittle lamb\r\nlittle lamb.";
let v: Vec<&str> = re.split_inclusive_left(text).collect();
assert_eq!(v, [
    "Mary had a little lamb",
    "\nlittle lamb",
    "\r\nlittle lamb.",
]);

Implementors§