// 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)^(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})$").unwrap();
let string = "Допустимые адреса
http://www.company.com
https://www.company.com
https://company.com
http://company.com
www.company.com
company.com
http://www.company.com/some
https://www.company.com/some
www.company.com/some
http://www.company.com/some%20address
https://www.company.com/some%20address
www.company.com/some%20address
http://www.company.com/?sidebar=buyerDetail
https://www.company.com/?sidebar=buyerDetail
www.company.com/?sidebar=buyerDetail
http://www.company.com/some/sidebar=buyerDetail
https://www.company.com/some/sidebar=buyerDetail
www.company.com/some/sidebar=buyerDetail
Недопустимые адреса
1http://www.company.com/some/sidebar=buyerDetail
1https://www.company.com/some/sidebar=buyerDetail
.http://www.company.com/some/sidebar=buyerDetail
.https://www.company.com/some/sidebar=buyerDetail
.http://www.company.com/some/sidebar=buyerDetail
.https://www.company.com/some/sidebar=buyerDetail
com/some/sidebar=buyerDetail
+=.company.com/some/sidebar=buyerDetail";
// 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/