A Rust clone of a Perl word-splitting program.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

14 lines
432 B

use exitfailure::ExitFailure;
use regex::{Regex, Replacer};
// I have idea what is happening here.
// https://docs.rs/regex/1.3.1/regex/trait.Replacer.html
pub fn replace_nonalpha<R: Replacer>(
src: &str,
mut rep: R,
) -> String {
let nonalpha = Regex::new(r"[^[:alpha:]]+").unwrap();
let dst = nonalpha.replace_all(src, rep.by_ref());
let dst = nonalpha.replace_all(&dst, rep.by_ref());
dst.into_owned()
}