Created
July 30, 2015 22:29
-
-
Save anonymous/cd705476576864f9220e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate regex; | |
use std::io::{Write, stderr}; | |
use regex::{Regex, Captures}; | |
type Error = Box<::std::error::Error + Send + Sync>; | |
fn captures<'t>(pat: &str, txt: &'t str) -> Result<Vec<Captures<'t>>, Error> { | |
let re = try!(Regex::new(pat)); | |
Ok(re.captures_iter(txt).collect()) | |
} | |
fn main() { | |
let caps = match captures(r"(\d+)", "aa 11 bb 22 cc 33") { | |
Ok(caps) => caps, | |
Err(err) => { | |
writeln!(&mut stderr(), "ERROR: {}", err).unwrap(); | |
::std::process::exit(1); | |
} | |
}; | |
for cap in &caps { | |
println!("{:?}", cap.at(1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment