// 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)%utilization\",.+:\"(?<utilization>[\d\.]+)"#).unwrap();
let string = "Dataframe row : {\"_c0\":{\"0\":null,\"1\":\"00:00:01\",\"2\":\"13:30:01\"},\"_c1\":{\"0\":null,\"1\":\"CPU\",\"2\":\"all\"},\"_c2\":{\"0\":\"Linux\",\"1\":\"%user\",\"2\":\"1.05\"},\"_c3\":{\"0\":\"3.10.0-1160.76.1.el7.x86_64\",\"1\":\"%nice\",\"2\":\"0.34\"},\"_c4\":{\"0\":\"(fraasdwhbdd1.de.db.com)\",\"1\":\"%system\",\"2\":\"0.83\"},\"_c5\":{\"0\":\"16\\/05\\/23\",\"1\":\"%iowait\",\"2\":\"0.05\"},\"_c6\":{\"0\":\"_x86_64_\",\"1\":\"%steal\",\"2\":\"0.00\"},\"_c7\":{\"0\":\"(8\",\"1\":\"%idle\",\"2\":\"97.73\"},\"_c8\":{\"0\":\"CPU)\",\"1\":\"%utilization\",\"2\":\"2.27\"}}.";
// 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/