Skip to content

Instantly share code, notes, and snippets.

@0xbe7a
Created January 30, 2018 18:14
Show Gist options
  • Save 0xbe7a/04cac7957ab5e051666c09138f477159 to your computer and use it in GitHub Desktop.
Save 0xbe7a/04cac7957ab5e051666c09138f477159 to your computer and use it in GitHub Desktop.
extern crate regex;
use regex::Regex;
fn main() {
let r = match Regex::new(&regex::escape(r"\/[a-z]{3}\/[0-9]{4}")) {
Ok(r) => r,
Err(e) => {
println!("Could not compile regex: {}", e);
return;
}
};
let string = "/dev/abc
/sys/3453
/esp/3scs";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = r.find_iter(string);
println!("{:?}", string);
for m in result {
println!("{:?}", m);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment