// 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)(?<date>\d+\-\d+\-\d+).(?<time>\d+:\d+:\d+).(?<timetaken>\d+).(?<cip>\d+\.\d+\.\d+\.\d+).(?<scstatus>\d+).(?<scaction>\S+).(?<scbytes>\d+).(?<csbytes>\d+).(?<csmethod>\S+).(?<csurischeme>\S+).(?<cshost>\S+).(?<csuriport>\d+).(?<csuripath>\S+).(?<csuriquery>\S+).(?<csusername>\S+).(?<csauthgroup>\S+).(?<shierarchy>\S+).(?<ssuppliername>\S+).(?<rscontenttype>\S+).(?<csreferer>\S+)."?(?<cs_user_agent>.+)"?."#).unwrap();
let string = "2014-03-27 12:39:32 20 10.71.15.207 304 TCP_HIT 367 1470 GET http www.computerworld.com 80 /elqNow/elqFCS.js - - - - 23.196.74.53 application/x-javascript http://www.computerworld.com/s/article/9247206/Gameover_malware_takes_aim_at_Monster.com_and_CareerBuilder.com \"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)\" OBSERVED \"Technology/Internet\" - 163.252.254.201 23.44.202.53 52809
";
// 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/