// 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"(?<type>[A-Z]{1})(?<subtype>[A-Z]{1})(?<country>[A-Z]{3})(?<last_name>[A-Z<]{25})(?<department>[A-Z0-9<]{3})(?<office>[0-9<]{3})\n(?<id_card>[A-Z0-9]{12})(?<id_check>[0-9]{1})(?<first_name>[A-Z<]{14})(?<birth_date>[0-9]{6})(?<birth_check>[0-9]{1})(?<gender>[MF]{1})(?<full_check>[0-9]{1})").unwrap();
let string = "IDFRALOISEAU<<<<<<<<<<<<<<<<<<<<<<<<
970675K002774HERVE<<DJAMEL<7303216M4
IDFRAPALERMO<<<<<<<<<<<<<<<<<<061773
1309061227772BIANCA<<HELLY<8911205F7
IDFRAPETE<<<<<<<<<<<<<<<<<<<<<952042
0509952018746NICOLAS<<PAUL<8206152M3";
// 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/