using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @".*(?:\+49|0049|\+\(49\)|\+43|0043|\+\(43\)).*";
string input = @"################################### 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
";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx