// 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)(<section[a-z="'\s]+>([\s\S]*?)<\/section>)"#).unwrap();
let string = "<chapter id=\"chap1\">
<para0><title></title></para0>
</chapter>
<chapter id=\"chap2\"> <title>THEORY</title>
<section id=\"Thoery\">
<title>theory Section</title>
<para0 verstatus=\"ver\">
<title>Theory Para 0 </title>
<text>blah blah</text>
</para0>
</section>
<section id=\"Next section\">
<title>title</title>
<para0>
<title>Title</title>
<text>blah blah</text>
</para0>
</section>
<section id=\"More sections\">
<title>title</title>
<para0>
<title>Title</title>
<text>blah blah</text>
</para0>
</section>
<section id=\"section\">
<title>title</title>
<para0>
<title>Title</title>
<text>blah blah</text>
</para0>
</section>";
let substitution = "$1";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", result);
}
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/