// 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#"[0-9. ]+([a-z.-]+).*\[(.*)\][\s"A-Z]*(/.*) HTTP/[12].[012]""#).unwrap();
let string = "10.101.2.114 www.voyage-prive.com - 94.23.212.183 - - [11/May/2017:06:25:39 +0200] \"GET /thematique/ventes/207761?from=feaee02fa292afd71911a4c63d2ed692&utm_medium=email&utm_source=NL&utm_campaign=standard&utm_term=NL2&utm_content=110517NLS20NL2VP_FR&ectrans=1 HTTP/1.1\" 200 11898 \"-\" \"(varnish-web)\" - - 1.083ms
10.101.2.114 www.voyage-prive.com - 78.200.34.180 - - [11/May/2017:06:25:39 +0200] \"GET /fiche-produit/details/207749/b1 HTTP/1.1\" 200 32128 \"http://www.voyage-prive.com/thematique/ventes\" \"Mozilla/5.0 (Linux; U; Android 4.4.2; fr-fr; GT-P5210 Build/KOT49H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30 (varnish-web)\" - - 0.085ms
10.101.2.114 www.voyage-prive.com - 80.215.46.226 - - [11/May/2017:06:25:39 +0200] \"GET /fiche-produit/details/208003 HTTP/1.1\" 200 44186 \"-\" \"Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Mobile/14A456 (varnish-web)\" - - 0.051ms
10.101.2.114 www.voyage-prive.com - 89.80.18.134 - - [11/May/2017:06:25:39 +0200] \"GET /search/doAjaxSearch?sid=208088&decode=true&version=2&with_dispos=1&culture=fr_FR&oid=3602628&with_catalog=true&papaya2=0 HTTP/1.1\" 200 18690 \"http://www.voyage-prive.com/fiche-produit/details/208088/b1\" \"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 (varnish-web)\" - - 0.014ms
10.101.2.114 www.voyage-prive.com - 89.80.18.134 - - [11/May/2017:06:25:40 +0200] \"GET /search/doAjaxSearch?sid=208088&decode=true&version=2&with_dispos=1&culture=fr_FR&oid=3602629&with_catalog=true&papaya2=0 HTTP/1.1\" 200 3759 \"http://www.voyage-prive.com/fiche-produit/details/208088/b1\" \"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 (varnish-web)\" - - 0.008ms
10.101.2.114 www.voyage-prive.com - 81.57.89.166 - - [11/May/2017:06:25:40 +0200] \"GET /fiche-produit/details/207756 HTTP/1.1\" 200 42503 \"-\" \"Mozilla/5.0 (iPad; CPU OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E304 (varnish-web)\" - - 0.045ms
10.101.2.114 www.voyage-prive.com - 212.83.158.193 - - [11/May/2017:06:25:40 +0200] \"GET /login/index HTTP/1.1\" 200 9555 \"-\" \"Python-urllib/2.6 (varnish-web)\" - - 0.054ms
10.101.2.114 www.voyage-prive.com - 10.110.2.254 - - [11/May/2017:06:25:40 +0200] \"GET /api/member/update?id_membre=5295731&culture=fr_FR HTTP/1.1\" 200 1387 \"-\" \"Phalcon HTTP/0.0.2 (Curl) (varnish-web)\" - - 0.023ms
10.101.2.114 www.voyage-prive.it - 212.83.158.193 - - [11/May/2017:06:25:40 +0200] \"GET /login/index HTTP/1.1\" 200 9042 \"-\" \"Python-urllib/2.6 (varnish-web)\" - - 0.052ms
10.101.2.114 www.voyage-prive.com - 78.118.109.58 - - [11/May/2017:06:25:41 +0200] \"GET /search/doAjaxMerchSdv?d[]=eu.fr.fr11.par&is_admin=0&sales_type=filtered&list=2&version=3&groupBy=isOnline&count=250&page=1&culture=fr_FR&onlySale=1 HTTP/1.1\" 200 15847 \"http://www.voyage-prive.com/thematique/ventes\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14 (varnish-web)\" - - 0.011ms";
// 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/