// 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)^9?[\d]{4}-[\d]{4}$").unwrap();
let string = "# 8 dígitos sem traço
12345678
92841742
83457854
# 9 dígitos sem traço
123457890
899879878
983457854
912345678
# 8 dígitos com traço
1234-5678
9284-1742
8345-7854
# 9 dígitos com traço
12345-7890
89987-9878
98345-7854
91234-5678";
// 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/