// 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)<(?<tagName>\w+)(([^<]*\/>)|(.*?\/(\k<tagName>)>))").unwrap();
let string = " <child name = \"child_name1\" type = \"child_type1\"> <subchild id = \"1\" auth=\"auth1\">Value1</subchild> </child> <child name = \"child_name2\" type = \"child_type2\"> <subchild id = \"2\" auth=\"auth1\">Value2</subchild> <subchild id = \"3\" auth=\"auth2\">Value3</subchild> <subchild id = \"4\" auth=\"auth3\"></subchild> <subchild id = \"5\" auth=\"auth3\"/> </child>";
// 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/