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

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