regex-split
The regex crate doesn't provide split_inclusive, which is found in the standard library for string, etc. There's an unstable feature that allows a regex to be used as the search pattern for a split, yadda yadda, etc., but who wants to use unstable these days?
Anyway, this library adds split_inclusive
and split_inclusive_left
, with the difference being that split_inclusive_left
places the delimiter at the beginning of the substring, where split_inclusive
places it at the end.
Usage
First, add the package.
$ cargo add regex-split
Then import regex_split::RegexSplit wherever you'd like to use the extra methods. Consuming the new methods is straightforward.
use RegexSplit;
// split_inclusive
let re = new.unwrap;
let text = "This is just\na set of lines\r\nwith different newlines.";
let v: = re.split_inclusive.collect;
assert_eq!;
// split_inclusive_left
let re = new.unwrap;
let text = "List of fruits:\n-apple\n-pear\n-banana";
let v: = re.split_inclusive_left.collect;
assert_eq!;
That's pretty much it.