// 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)<field>[\s\S]+?(?=<\/field>)").unwrap();
let string = "<field>
<item value=\"1\" description=\"Mostly A's\" />
<item value=\"2\" description=\"Mostly B's\" />
<item value=\"3\" description=\"Mostly C's\" />
<item value=\"4\" description=\"Mostly D's\" />
<item value=\"5\" description=\"Mostly failures\" />
<item value=\"6\" description=\"Mostly incompletes\" />
<item value=\"7\" description=\"Not applicable\" />
</field>
<field>
<item value=\"1\" description=\"Mostly A's\" />
<item value=\"2\" description=\"Mostly B's\" />
<item value=\"3\" description=\"Mostly C's\" />
<item value=\"4\" description=\"Mostly D's\" />
<item value=\"5\" description=\"Mostly failures\" />
<item value=\"6\" description=\"Mostly incompletes\" />
<item value=\"7\" description=\"Not applicable\" />
</field>
";
// 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/