// 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".+>([^>]+)$").unwrap();
let string = "<div><pre style=\"font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px\"><code style=\"font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)\"><span><span style=\"color:rgb(51,51,51);font-weight:bold\">function</span> <span style=\"color:rgb(153,0,0);font-weight:bold\">syntaxHighlighting</span><span>()</span> </span>{
<span style=\"color:rgb(51,51,51);font-weight:bold\">var</span> n = <span style=\"color:rgb(0,128,128)\">33</span>;
<span style=\"color:rgb(51,51,51);font-weight:bold\">var</span> s = <span style=\"color:rgb(221,17,68)\">\"hello, こんにちは\"</span>;
<span style=\"color:rgb(0,134,179)\">console</span>.log(s);
}
</code></pre>
";
// 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/