using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(\+55)?[\s]?\(?(\d{2})?\)?[\s-]?(9?\d{4}[\s-]?\d{4})$";
string input = @"+55(16)91555-3456
22 98671 1032
+55 7134764819
(23)99378-4366
+5598683 1021
+551199603-3412
55 98214 9064
(55)98330-7156
(82) 936147156
+552430431084
2140028922
40028922
21 40028922
(21) 4002-8922
+55 21 4002 8922
+55(21)4002-8922
+55986320291";
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