// 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"(?Us)\[(collapse|collapse in)\]\s*<(h[2-4])>(.*)<\/\2>(.*)\s*\[\/collapse\]").unwrap();
let string = "<p>Bene eros jus neo olim pecus suscipit. </p>
[collapse in]
<h2>titel</h2>
<p>Illum iriure neo populus refoveo.</p>
<h3>titel</h3>
<p>Illum iriure neo populus refoveo.</p>
<h2>titel</h>
<p>Illum iriure neo populus refoveo.</p>
[/collapse]
[collapse]
<h3>titel2</h3>
<p>Illum iriure neo populus refoveo.</p> [/collapse]";
let substitution = "<\\2 data-target=\"#\\3\" data-toggle=\"\\1\">\\3</\\2>\\n<div id=\"\\3\" class=\"collapse\">\\4</div>";
// 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/