// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m)(?:\d+\s+)(\w+)(?:\s+)(\w+)").unwrap();
let string = " Id Name State
----------------------------------------------------
14 vm2 running
19 vm7 running
22 vm10 running
27 vm11 running
36 vm9 running
38 vm12 running
43 vm6 running
46 vm1 running
49 vm4 running
63 vm5 running
65 vm8 running
67 vm3 running
";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/