// 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#"(?m)<section.*id="section[\d]*"[\s\S]*?<\/section>"#).unwrap();
let string = "<!DOCTYPE html>
<html lang=\"en\">
<head>
<title>Whatever</title>
</head>
<body>
<section class=\"all-classes\" id=\"section1-do-not-remove-section\">
content2
content
</section>
<section class=\"all-classes\" id=\"section2\">
content
content2
</section>
</body>
<section class=\"all-classes\" id=\"section3\">
content
<div class=\"all-classes\" id=\"section4\">
anything
whatever
</div>
</section>
<section class=\"all-classes\" id=\"section5-do-not-remove-section\">
content
</section>
<section class=\"all-classes\" id=\"section6\">
content
</section>
<section class=\"all-classes\" id=\"section7\">
content
</section>
";
// 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/