using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(?:\+44\s?|0)[1238]\d\s?(?:\d\s?){7,8}$";
string input = @"# 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
";
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