// 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)^(?:(?<network_srcIpv4>(?:[0-9]{1,3}\.){3}[0-9]{1,3})|(?<network_srcIpv6>[:\-0-9a-fA-F]+?)|(?<network_srcHost>.+?)) - (?:-|(?<user_username>.+)) \[(?<time>.*)\] \"(?<application_cmd>(?<application_http_method>[A-Z]+)\s(?:(?<application_proto>.*?)://)?(?<network_fqdn>[^/]*?)(?:\:(?<network_dstPort>\d+))?(?<file_path>/.*?)?(?:\?(?<application_http_queryString>.*?))?(?: HTTP/(?<application_http_version>[0-9\.]+)?))\" (?<application_http_status>\d+) (?<application_len>\d+) (?:"(?:-|(?<application_http_referrer>.*))")? (?:"(?:-|(?<application_http_userAgent>.*))")$"#).unwrap();
let string = "218.1.111.50 - - [13/Mar/2005:10:36:12 -0500] \"GET http://www.yahoo.com/ HTTP/1.1\" 403 2898 \"-\" \"Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)\"
24.23.244.160 - - [13/Mar/2005:13:48:40 -0500] \"GET /scripts/..%25%35%63../winnt/system32/cmd.exe?/c+dir HTTP/1.0\" 404 1041 \"-\" \"-\"";
// 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/