// 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"(?imu)^(?:https?:\/\/)?(?:(?:[\pL0-9-]+)\.)+[\pL]{2,}(?:\/.*)?$").unwrap();
let string = "http://google.com
https://google.com
http://google.com/
https://google.com/
http://g oogle.com
http://google.com/somepath
https://g oogle.com/somepath
https://g_oogle.com/somepath
google.com
google.com/somepath
goo gle.com/badpath
кириллица.укр
кирилл ица.укр
кириллица.укр/путь
кирилл01ица.укр
кирилли-ца.укр/путь
собдомен.кириллица.укр
собдомен.кириллица.укр/путь
2саб.1саб.домен.укр
2саб.1с-аб.до мен.укр";
// 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/