// 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)^([2-9]{1})([0-9]{2})([\s.-]?)([2-9]{1})([0-9]{2})([\s.-]?)([0-9]{4})$").unwrap();
let string = "212-222-1010
(203)753-5678
(203) 753-5678
201-853-6909
800-289-2583
215 5551212
515555121200000
201.853.6909
201 853 6909
201-853-6909
201 853 6909
101.853.6909
1018536909
666-666-6669
(208) 555-1234
666-666-666
666 666 6666
666.666.6666
555 555 5555
222-222-2222
123-123-132
236-548-9888";
// 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/