Militsa

06. Match Phone Number

Nov 29th, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace Study
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string phonenomber = Console.ReadLine();
  15.             String pattern = @"\+[359]+(-| )[2]\1[\d]{3}\1[\d]{4}\b";
  16.  
  17.             MatchCollection matches = Regex.Matches(phonenomber, pattern);
  18.  
  19.             List<string> result = new List<string>();
  20.             foreach (var item in matches)
  21.             {
  22.                 result.Add(item.ToString());
  23.             }
  24.             Console.WriteLine(String.Join(", ", result));
  25.         }
  26.     }
  27. }
Add Comment
Please, Sign In to add comment