Skip to content

Instantly share code, notes, and snippets.

@mhristache
Created January 1, 2017 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhristache/30d5fd6562ec98015634c48e847bdf95 to your computer and use it in GitHub Desktop.
Save mhristache/30d5fd6562ec98015634c48e847bdf95 to your computer and use it in GitHub Desktop.
Rust regex issue
extern crate regex;
use std::borrow::Cow;
fn main() {
let input = "\x1b[34mfoo";
assert_eq!(strip_formatting(input), "foo");
}
// Regex 0.1
//
//fn strip_formatting<'t>(input: &'t str) -> String {
// let re = regex::Regex::new(r#"\x1B\[.+?m"#).unwrap();
// re.replace_all(input, "")
//}
// Regex 0.2
//
fn strip_formatting<'t>(input: &'t str) -> Cow<'t, str> {
let re = regex::Regex::new(r#"\x1B\[.+?m"#).unwrap();
re.replace_all(input, "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment