// 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"(?mx)<([^\/>]+)>((([^\<]+)|(?R))*)<\/\1>").unwrap();
let string = "<ul><li><span>qwe</span><b></b></li><div>sometext</div></ul><div></div>.
<li><span>qwe</span><div>s</div></li>
<b></b>
<ul><li><span>qwe</span><b></b></li><div>sometext</div></ul><div></div>.
some text <tag>some|another|text</tag> and anything else
str = <<'EOT'
Это <!--пример текста--> с5
<a href=\"#\">какой-то</a> <br>разметкой <br />
<b class=\"11\">и</b> <amg src=\"1\">
<area>непарными</area> <strong>
тегами</strong> и, <!--коментами-->,
<ul id=\"w\"> <li id=\"id\" class=\"class\">1</li></ul><div></div>.
<u class=\"ну и даже так\" />
EOT";
// 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/