Skip to content

Instantly share code, notes, and snippets.

@mhristache
Created January 1, 2017 16:16
Embed
What would you like to do?
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