// 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#"(<h([1-3]{1})[^>]*?(?! id)(?:id=\"([^\"]*)\"[^>]*)?>)(.*)<\/h\2>|<!--nextpage-->"#).unwrap();
let string = "<h1>Test</h1>
<h1 id=\"test\">Test</h1>
<h2 test=\"testattr\" id=\"id\">Test</h2>
<h3 id=\"id\" test=\"test\">Test</h3>
<h3 test=\"test\" id=\"test\" test=\"test\">TEST</h3>
<h4></h4>
test
sdlfkdslf
<table>
h1
<!--nextpage-->";
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/