// 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)^XXX-\d{4}-((?![XYT])[A-Z]){4}$").unwrap();
let string = "XXX-0000-XBCD
XXX-0000-AXCD
XXX-0000-ABXD
XXX-0000-ABCX
XXX-0000-XXCD
XXX-0000-XBXD
XXX-0000-XBCX
XXX-0000-AXXD
XXX-0000-AXCX
XXX-0000-ABXX
XXX-0000-XXXX
XXX-0000-AB1D
XXX-0000-A%CD
XXX-0000-ABCDE
XXX-0000-ABCDX
AXXX-0000-ABCD
XXX-A0000-ABCD
XXX-0000-ABCD
";
// 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/