// 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#"(?is)<li id="hit-[0-9]+">(.*?)<\/li>"#).unwrap();
let string = "<li id=\"hit-11\">
<h2>
<a href=\"http://www.sonymobile.com/gb/products/phones/xperia-z2/\" class=\"heading\">Xperiaâ„¢ <b>Z2</b> | Android Phone - Sony Smartphones (UK)</a>
</h2>
<p><b>...</b> Xperiaâ„¢ <b>Z2</b>. The world&#39;s best camera and camcorder in a waterproof<br> smartphone*. <b>...</b> The Xperia <b>Z2</b> makes the moment unforgettable. Meet Xperia <b>...</b> </p>
<p>
<a href=\"http://www.sonymobile.com/gb/products/phones/xperia-z2/\" class=\"link\">http://www.sonymobile.com/gb/products/phones/xperia-z2/</a>
</p>
</li>
<li id=\"hit-2\">
<h2>
<a href=\"http://www.sonymobile.com/gb/products/phones/xperia-z2/accessories/\"
class=\"heading\">Xperia <b>Z2</b> Accessories | Smartphone accessory - Sony <b>...</b></a>
</h2>
<p><b>...</b> Xperiaâ„¢ <b>Z2</b>. The world&#39;s best camera and camcorder in a waterproof<br> smartphone*. <b>...</b> Then watch your life played back to you on your Xperia <b>Z2</b>. <b>...</b> </p>
<p>
<a href=\"http://www.sonymobile.com/gb/products/phones/xperia-z2/accessories/\"
class=\"link\">http://www.sonymobile.com/gb/products/phones/xperia-z2/accessories/</a>
</p>
</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/