// 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+) \[([\w:\/]+\s[+\-]\d{4})\] "GET (.+?) HTTP\/1\.1" (\d{3}) (\d+) "([^"]+)" "([^"]+)""#).unwrap();
let string = "79.133.215.123 - - [14/Jun/2014:10:30:13 -0400] \"GET /home HTTP/1.1\" 200 1671 \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
162.235.161.200 - - [14/Jun/2014:10:30:13 -0400] \"GET /department/apparel/category/featured%20shops/product/adidas%20Kids'%20RG%20III%20Mid%20Football%20Cleat HTTP/1.1\" 200 1175 \"-\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.76.4 (KHTML, like Gecko) Version/7.0.4 Safari/537.76.4\"
39.244.91.133 - - [14/Jun/2014:10:30:14 -0400] \"GET /department/fitness HTTP/1.1\" 200 1435 \"-\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
150.47.54.136 - - [14/Jun/2014:10:30:14 -0400] \"GET /department/fan%20shop/category/water%20sports/product/Pelican%20Sunstream%20100%20Kayak/add_to_cart HTTP/1.1\" 200 1932 \"-\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
217.89.36.129 - - [14/Jun/2014:10:30:14 -0400] \"GET /view_cart HTTP/1.1\" 200 1401 \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0\"
36.44.59.115 - - [14/Jun/2014:10:30:15 -0400] \"GET /department/footwear/category/cardio%20equipment HTTP/1.1\" 200 386 \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0\"
11.252.83.179 - - [14/Jun/2014:10:30:15 -0400] \"GET /view_cart HTTP/1.1\" 200 1726 \"-\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
56.251.19.230 - - [14/Jun/2014:10:30:15 -0400] \"GET /department/footwear/category/fitness%20accessories HTTP/1.1\" 200 2076 \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
137.95.229.186 - - [14/Jun/2014:10:30:16 -0400] \"GET /department/fan%20shop/category/fishing/product/Field%20&%20Stream%20Sportsman%2016%20Gun%20Fire%20Safe HTTP/1.1\" 200 1413 \"-\" \"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
100.98.159.99 - - [14/Jun/2014:10:30:16 -0400] \"GET /department/fan%20shop/category/water%20sports/product/Pelican%20Sunstream%20100%20Kayak HTTP/1.1\" 200 396 \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
137.95.229.186 - - [14/Jun/2014:10:30:16 -0400] \"GET /home HTTP/1.1\" 200 1473 \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
86.214.1.70 - - [14/Jun/2014:10:30:17 -0400] \"GET /department/fan%20shop HTTP/1.1\" 200 771 \"-\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36\"
18.168.113.227 - - [14/Jun/2014:10:30:17 -0400] \"GET /support HTTP/1.1\" 200 1321 \"-\" \"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
133.20.136.170 - - [14/Jun/2014:10:30:18 -0400] \"GET /home HTTP/1.1\" 200 1238 \"-\" \"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
137.95.229.186 - - [14/Jun/2014:10:30:18 -0400] \"GET /home HTTP/1.1\" 200 1797 \"-\" \"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
100.158.186.50 - - [14/Jun/2014:10:30:18 -0400] \"GET /home HTTP/1.1\" 200 878 \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36\"
36.44.59.115 - - [14/Jun/2014:10:30:19 -0400] \"GET /checkout HTTP/1.1\" 200 1551 \"-\" \"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko\"
";
// 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/