// 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#"(?mx)(?P<host>[\d.]+)[-\s]+
(?P<user_name>\w+)\s+
\[(?P<time>[^][]+)\]\s+
"(?P<request>[^"]+)""#).unwrap();
let string = "30.95.91.251 - larson8319 [21/Jun/2019:16:02:02 -0700] \"PUT /one-to-one/whiteboard HTTP/1.0\" 401 7270
";
// 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/