1 extern crate onig;
2
3 use onig::*;
4 use std::env;
5 use std::io;
6 use std::io::prelude::*;
7 use std::collections::HashMap;
8
main()9 fn main() {
10 let mut regexes = HashMap::new();
11 for arg in env::args().skip(1) {
12 println!("Compiling '{}'", arg);
13 let regex_compilation = Regex::new(&arg);
14 match regex_compilation {
15 Ok(regex) => {
16 regexes.insert(arg, regex);
17 }
18 Err(error) => {
19 panic!("{:?}", error);
20 }
21 }
22 }
23
24 let stdin = io::stdin();
25 for line in stdin.lock().lines() {
26 if let Ok(line) = line {
27 for (name, regex) in regexes.iter() {
28 let res = regex.captures(&line);
29 match res {
30 Some(captures) => for (i, mat) in captures.iter().enumerate() {
31 println!("{} => '{}'", i, mat.unwrap());
32 },
33 None => println!("{} => did not match", name),
34 }
35 }
36 }
37 }
38 }
39