Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. extern crate regex;
  2.  
  3. use regex::Regex;
  4. use std::borrow::Cow;
  5.  
  6.  
  7. fn main() {
  8. let out = do_regex("hello foo");
  9. println!("{}", out);
  10. }
  11.  
  12. fn do_regex<'a>(txt: &'a str) -> Cow<str> {
  13. let rx = Regex::new("foo").unwrap();
  14. let out = rx.replace_all(txt, "bar");
  15. let out2 = rx.replace_all(&out, "blah");
  16. out2
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement