// 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)<a href="javascript:void\(0\)"[^>]*>(.*?)id="sw-slots-grid-line-break""#).unwrap();
let string = "<div id=\"tmm-grid-swatch-HARDCOVER\" class=\"a-column a-span6 a-text-left swatchElement selected celwidget\" role=\"listitem\" data-csa-c-id=\"rqzqyx-arj8qg-jifnrc-pelgtz\" data-cel-widget=\"tmm-grid-swatch-HARDCOVER\"> <span class=\"a-button a-button-selected a-spacing-none a-button-toggle format\" id=\"a-autoid-2\"><span class=\"a-button-inner\"><a href=\"javascript:void(0)\" role=\"radio\" aria-checked=\"true\" aria-current=\"page\" class=\"a-button-text a-text-left\" id=\"a-autoid-2-announce\"> <span class=\"slot-title\">
<span aria-label=\"Hardcover Format:\">Hardcover</span> <br> </span>
<span class=\"slot-price\">
<span aria-label=\"$16.94\" class=\"a-size-base a-color-price a-color-price\"> $16.94 </span> </span>
<br id=\"sw-slots-grid-line-break\">
</a></span></span> </div>";
// 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/