// 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"(?sm)^(Sensor #0 -> (?P<EXT>\d+[.]\d+)(?:.*?Sensor #2 -> )(?P<INT>\d+[.]\d+)(?:.*?)(?P<DATE>\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}:\d{2}))").unwrap();
let string = "system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 87.81
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:50system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.110
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:51system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.206
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:52system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 87.176
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:53system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.110
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:54system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.110
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:55system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 87.176
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:56system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 87.81
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:57system tmp gettemp 0
Sensor #0 -> 68.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.15
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:58system tmp gettemp 0
Sensor #0 -> 68.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.15
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:59system tmp gettemp 0
Sensor #0 -> 68.0
OK
dbg_cpu0> 2016/11/23 11:05:002016/11/23 11:05:012016/11/23";
// 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/