// 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)^(ABC)_([0-9]{4})_([0-9]+\.[0-9]+\.[0-9]+)(_[a-zA-Z])?(_[a-zA-Z]+)?\.xyz$").unwrap();
let string = "ABC_0000_0.0.0.xyz
Group 1 : ABC
Group 2 : 0000
Group 3 : 0.0.0
Group 4 : <empty>
Group 5 : <empty>
ABC_0001_0.1.0_N.xyz
Group 1 : ABC
Group 2 : 0001
Group 3 : 0.1.0
Group 4 : _N
Group 5 : <empty>
ABC_0002_1.1.2_foo.xyz
Group 1 : ABC
Group 2 : 0002
Group 3 : 1.1.2
Group 4 : <empty>
Group 5 : _foo
ABC_0002_42.42.42_N_bar.xyz
Group 1 : ABC
Group 2 : 0002
Group 3 : 42.42.42
Group 4 : _N
Group 5 : _bar";
// 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/