// 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"(?mx)^
(?<batch_number>\d{2})-
(?:
(?<component>QQ|CO|CG)
(?<target_group>[AS])
(?<paper>P)?
)
(?:-
(?<domain>(?:LDW|MAT|REA|SCI|XYZ)
(?<division>[abc])?
)
)?
-(?<authoring_point>[TN])
$").unwrap();
let string = "01-COS-SCIa-N
02-COS-SCIb-N
03-COS-SCIc-N
04-QQS-N
05-QQA-N
06-COS-LDW-N
07-COS-XYZ-N
08-CGA-SCI-N
11-COS-MATa-T
12-COS-MATb-T
13-COS-REAa-T
14-COS-REAb-T
15-COS-SCIa-T
16-COS-SCIb-T
17-CGA-SCI-T
18-CGA-MAT-T
19-CGA-REA-T
21-COSP-REAa-T
22-COSP-REAb-T
23-COSP-MATa-T
24-COSP-MATb-T
25-COSP-SCIa-N
26-COSP-SCIa-T
27-QQSP-N
28-QQAP-N
29-COSP-XYZ-N
";
// 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/