// 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)^(?:\+44\s?|0)[1238]\d\s?(?:\d\s?){7,8}$").unwrap();
let string = "# Standard
01386 444400
01386444400
+441386444400
+44 1386 444400
+44 1386444400
# 5 Digit
01386 41204
0138641204
+44138641204
+44 1386 41204
+44 138641204
# 3 Digit area codes (e.g. London)
+442074343046
02074343046
020 74343046
020 7434 3046
# 4 Digit area codes (e.g. Leeds)
+441133971337
01133971337
0113 3971337
# Commercial
08451772266
0845 1772266
# Mobile number (should not match)
07999888777
+447999888777
07999 888 777
+44 7999888777
";
// 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/