// 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#"(?i)href=(["|\']\/?["|\'])"#).unwrap();
let string = "<li><a href=\"http://www.userlink1.com/my/page.html\" custattr=\"value1\"><img alt=\"Userlink\" class=\"common_link_class\" height=\"123\" src=\"pic0.png\" width=\"123\" style=\"width: 123px;\"></a></li><li><a href=\"//www.socnet1.com/username1.css\" custattr=\"value1\"><img alt=\"Socnet1\" class=\"common_link_class\" height=\"123\" src=\"pic1.png\" width=\"123\" style=\"width: 123px;\"></a></li><li><a href=\"//www.socnet2.com/username1.js\" custattr=\"value1\"><img alt=\"Socnet2\" class=\"common_link_class\" height=\"123\" src=\"pic2.png\" width=\"123\" style=\"width: 123px;\"></a></li><li><a href=\"mailto:useralias1@unlikely.zyx321.usermail.net\" custattr=\"value1\"><img alt=\"Usermail\" class=\"common_link_class\" height=\"123\" src=\"pic3.png\" width=\"123\" style=\"width: 123px;\"></a></li><li><a href=\"/www.userlink2.com/my/page.php?id=2&ok=1\" custattr=\"value1\"><img alt=\"Userlink\" class=\"common_link_class\" height=\"123\" src=\"pic4.png\" width=\"123\" style=\"width: 123px;\"></a></li>
";
// result will be a tuple containing the start and end indices for the first match in the string
let result = regex.captures(string);
let (start, end) = match result {
Some((s, e)) => (s, e),
None => {
// ...
}
};
println!("{}", &string[start, end]);
}
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/