// 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{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \S+ \(\S+\) - flush done sketch={flushed=(\d+) total=(\d+) pruned=(\d+)} num_org_metric=\d+ since_ms=(\d+)ms dt=[-+]?([0-9]*(\.[0-9]*)?[a-z]+)+").unwrap();
let string = "2018-03-05 22:52:52 INFO (app.go:391) - flush done sketch={flushed=264557 total=57979680 pruned=295} num_org_metric=448 since_ms=10964ms dt=2.2392s
2018-03-05 22:53:01 INFO (app.go:391) - flush done sketch={flushed=171045 total=57954960 pruned=253} num_org_metric=448 since_ms=9377ms dt=1.616403s
2018-03-05 22:53:10 INFO (app.go:391) - flush done sketch={flushed=190064 total=57933000 pruned=297} num_org_metric=448 since_ms=9366ms dt=982.968ms
2018-03-05 22:53:20 INFO (app.go:391) - flush done sketch={flushed=153243 total=57932520 pruned=89} num_org_metric=448 since_ms=9908ms dt=891.573ms";
// 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/