// 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.*?>(.*?)</a>)\s*<ul").unwrap();
let string = "<ul>
<li>
<a href=\"#o\">Первый</a>
</li>
<li>
<a href=\"#v\">Второй</a>
</li>
<li>
<a href=\"#t\">Третий</a>
</li>
<li>
<a href=\"#ch\">Четвертый</a>
</li>
<li>
<a href=\"#p\">ПÑтый</a>
</li>
<li>
<a href=\"#test\">ШеÑтой</a>
<ul>
<li>
<a href=\"#so\">ШеÑтьОдин</a>
</li>
<li>
<a href=\"#sd\">ШеÑтьДва</a>
</li>
<li>
<a href=\"#st\">ШеÑтьТри</a>
</li>
<li>
<a href=\"#sc\">ШеÑтьЧетыре</a>
</li>
<li>
<a href=\"#sp\">ШеÑтьПÑть</a>
</li>
<li>
<a href=\"#ss\">ШеÑтьШеÑть</a>
</li>
<li>
<a href=\"#sss\">ШеÑтьСемь</a>
</li>
<li>
<a href=\"#sv\">ШеÑтьВоÑемь</a>
</li>
<li>
<a href=\"#sd\">ШеÑтьДевÑть</a>
</li>
</ul>
</li>
</ul>";
// 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/