// 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)(?x)(
# phone number
(\+1)?
(\s)?
(\(\d\d\d\))? #area code optional
(\s|-) # first separator
\d\d\d # first 3 digits
- # Separator
\d\d\d\d # last 4 digits
)").unwrap();
let string = "+1 (786) 665-5397
+1 (786) 773-7145
+1 (786) 804-8869
+1 (786) 806-5097
+1 (786) 856-7950
+1 (786) 862-2875
+1 (786) 915-7830
+1 (786) 991-4304
+1 (857) 334-1162
+1 (862) 944-0090
+1 (863) 307-5291
+1 (914) 826-4343
+1 (918) 992-1382
+1 (954) 226-7037";
// 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/