// 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)^(?P<reducer>\w+)\(\)\s+of\s+query\((?P<dashboardUID>\w+)\/(?P<panelID>\d+)\/(?P<metric>.+),\s+(?P<from>\w+),\s+(?P<to>\w+)\)\s+is\s+(?P<evaluator>\w+)\((?P<params>-*\d*[\.,\s]*\d*)\)\s*(for\s+\((?P<for>\w+)\))*\s*(every\((?P<every>\w+)\))*\s*$").unwrap();
let string = "avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is below(14)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is below(0.4)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is novalue()
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is withinrange(4, 88)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is withinrange(4, 88) for (1m)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is withinrange(4, 88) for (1m) every(1m)
avg() of query(summary/152/tx-avg, 1m, now) is below(5000)
avg() of query(summary/152/tx-avg, 1m, now) is below(-5000)";
// 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/