// 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)^(?=.{10,15}$)(?=.*(?:.*\d){10}.*$)([\(\)\p{Zs}.-]*[0-9]{3}[\(\)\p{Zs}.-]*[0-9]{3}[\(\)\p{Zs}.-]*[0-9]{4})$").unwrap();
let string = "(501) 555 1234
(501)-555.1234
501-555-1234
501.555.1234
501 555 1234
501) 343-2233
(501 343-2233
(501. 343-2233
5013432233
800-..555-1234
(.8005551234
*-(.8005551234
501*555-1234
-(.80055512 41
501_555_1234
555-1234
800-...........555-1234
013432233
1. The string must be 10-15 total characters in length.
2. Must contain exactly 10 digits within string.
3. Can contain \"(\", \")\" , \" \", \".\", or \"-\" delimiters within the string.
4. It doesn't matter how many delimiters are grouped as long as numbers are grouped in {3}{3}{4}.";
// 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/