// 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)^(\+55)?[\s]?\(?(\d{2})?\)?[\s-]?(9?\d{4}[\s-]?\d{4})$").unwrap();
let string = "+55(16)91555-3456
22 98671 1032
+55 7134764819
(23)99378-4366
+5598683 1021
+551199603-3412
55 98214 9064
(55)98330-7156
(82) 936147156
+552430431084
2140028922
40028922
21 40028922
(21) 4002-8922
+55 21 4002 8922
+55(21)4002-8922
+55986320291";
// 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/