// 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#"(?mi)(<(?!\/)[a-zA-Z\-0-9]+?(?:[\s]*?[a-zA-Z\-0-9]+?(?:=(?:"[\s\S]*?"|'[\s\S]*?')){0,1})*?[\s]*?\/{0,1}>)|(<\/[\S\s]+?>)|(<!--[\s\S]*?-->)"#).unwrap();
let string = "<div class=\"main\">
<div>
<form id=\"cadastro\">
<input value=\"text\" />
</form>
</div>
<div>
<div>
<h1>Lorem ipsum dolor sit amet</h1>
<p>Lorem ipsum dolor sit amet</p>
</div>
</div>
<!-- sad asd asdasds adasd -->
</div>
<div>
<ul>
<li>item 1</li>
</ul>
teste
</div>";
// 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/