// 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?:\/\/)?([\w\Q$-_+!*'(),%\E]+\.)+(\w{2,63})(:\d{1,4})?([\w\Q/$-_+!*'(),%\E]+\.?[\w])*\/?$").unwrap();
let string = "http://google.com
https://google.com
http://www.google.com
www.google.com
www.google.de:8080
www.test123.de
www.domain.com.de.whatever.to
www.google
h4xx0!2.net
page.to
hallo.to/test/whatever
hallo.to/test/whatever.cgi
www.google.com/startpage.html/
www.google.!!!
www..com
http://blabla.computer.de/.......................";
// 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/