// 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)<a\s.*href\s?=\s?["'](\bmailto:\b|\bhttp:\/\/\b|\bhttps:\/\/\b).*["'].*?>.*?<\/a>"#).unwrap();
let string = "<a style=\"\" href=\"https://www.dr.dk'>click here</a>
<a style=\"\" href=\"http://www.dr.dk'>click here</a>
<a href = \"http://www.dr.dk'>click here</a>
<ahref=\"https://www.dr.dk'>click here</a> Error in tag
<a href = https://www.dr.dk>click here</a> No quote marks
<a href=\"https://www.dr.dk\"> c l i c k h e r e </a>
<a href=\"mailto:ghf\">mail</a>
<a href=\"https://www.dr.dk\" class=\"link\"> c l i c k h e r e </a>
<a href =\"https://www.dr.dk\" class=\"link\"> c l i c k h e r e </a>
<A HREF = \"http://\">hej</a> <-No link
";
// 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/