// 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"<a[^>]*href\s*=(?<HRef>[^>]+)>").unwrap();
let string = "<html><head>
<title>Simple</title>
</head>
<body>
<div id=\"Content\" style=\"padding: 5px;\">
<p><a href=\"http://confluence:8080/download/attachments/8618175/Text.txt?version=1&modificationDate=1484637732181\">Text.txt</a><br/>
<span class=\"image-wrap\" style=\"\"><img src=\"http://confluence:8080/download/attachments/8618175/add-button-blue-hi.png?version=1&modificationDate=1484562338796\" style=\"border: 1px solid black\" /></span><br/>
<span class=\"image-wrap\" style=\"\"><a class=\"confluence-thumbnail-link 300x200\" href='http://confluence:8080/download/attachments/8618175/attachment.jpg'><img src=\"http://confluence:8080/download/thumbnails/8618175/attachment.jpg\" style=\"border: 1px solid black\" /></a></span></p>
</div>
</body></html>";
// 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/