// 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.]+\s-\s\[[^\]]+\]\s"[^"]+"\s\["[\w=-]+"\s:\s"[\w=-]+"\]\s-\s"[^"]+"\s"[^"]+"$"#).unwrap();
let string = "96.154.64.194 - [17/Sep/2015:10:17:30 +0000] \"GET /?utm_source=gl&utm_medium=email&utm_campaign=kok HTTP/1.1\" [\"uid=210FDE53A08FF955138C3C6502030303\" : \"-\"] - \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0\"
96.154.64.194 - [17/Sep/2015:10:17:30 +0000] \"GET /?utm_source=gl&utm_medium=email&utm_campaign=kok HTTP/1.1\" [\"uid=210FDE53A08FF955138C3C6502030303\" : \"-\"] - \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0\"91.154.64.194 - [17/Sep/2015:10:10:33 +0000] \"GET /e.gif?chto_smotrish? HTTP/1.1\" [\"uid=210FDE53A08FF955138C3C6502030303\" : \"-\"] - \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0\"
remote_addr - [time] \"query\" [\"uid\" : \"uid\"] - \"referrer\" \"user_agent\"";
// 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/