// 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)<li><a.+?>(.+)?<\/.+>").unwrap();
let string = "!-- The following setting enables collapsible lists -->
<p>
<a href=\"#human\">Human</a></p>
<p class=\"collapse-section\">
<a class=\"collapsed collapse-toggle\" data-toggle=\"collapse\"
href=#mammals>Mammals</a>
<div class=\"collapse\" id=\"mammals\">
<ul>
<li><a href=\"#alpaca\">Alpaca</a>
<li><a href=\"#armadillo\">Armadillo</a>
<li><a href=\"#sequence_only\">Armadillo</a> (sequence only)
<li><a href=\"#baboon\">Baboon</a>
<li><a href=\"#bison\">Bison</a>
<li><a href=\"#bonobo\">Bonobo</a>
<li><a href=\"#brown_kiwi\">Brown kiwi</a>
<li><a href=\"#bushbaby\">Bushbaby</a>
<li><a href=\"#sequence_only\">Bushbaby</a> (sequence only)
<li><a href=\"#cat\">Cat</a>
<li><a href=\"#chimp\">Chimpanzee</a>
<li><a href=\"#chinese_hamster\">Chinese hamster</a>
<li><a href=\"#chinese_pangolin\">Chinese pangolin</a>
<li><a href=\"#cow\">Cow</a>
<li><a href=\"#crab-eating_macaque\">Crab-eating_macaque</a>
<div class=\"gbFooterCopyright\">
© 2017 The Regents of the University of California. All
Rights Reserved.
<br>
<a href=\"https://genome.ucsc.edu/conditions.html\">Conditions of
Use</a>
</div>";
// 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/