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