// 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)^(?:\+4[39]|004[39]|0|\+\(49\)|\(\+49\))\s?(?=(?:[^\d\n]*\d){10,12}(?!\d))(\()?[19][1567]\d{1,2}(?(1)\))\s?\d(?:[ /-]?\d)+").unwrap();
let string = "################################### This is allowed ##########################
+49 15207930698
+49 15207955279
+49 1739341284
+49 1626589266
+49915175461907
+4915207930698
+491635556416
017687400179
015903900297
015175355164
015175354885
01771789427
+49 915175461907
+43 915175461907
+49159039012341
+43159039012341
+4915207829969
+4917697400179
+4915903904567
+4915902944599
+4915902944599
+4915903904567
+491739341284
+431739341284
+49 176 97 456 123
0176 79 123 17 9
0176 97 50 01 79
0176 79 123 179
0174 80123179
0049 915175461907
0043 915175461907
0049159039012341
0043159039012341
004915207829969
(+49) 17697123456
+(49) (1739) 34 12 84
+49 (1739) 34-12-84
############################################################################################
################################### This is NOT allowed ####################################
012345678901234
123w345345345345
0123456789101191919
### Too short
+49 15902
+49 1590123
+49 15903567
+49 177178796
+49 757130309
+4915902
+491590123
+4915903567
+49177178796
+49757130309
### Too long
+49 1590345985412
+491590345985412
### Not German and not Austrain format
+12127319863
+13322014056
+12126712234
+427532697710
+417868150810
+287533002875
";
// 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/