martinvalchev

Match_Phone_Number

Feb 21st, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Match_Phone_Number
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.  
  15.             string rg = @"\+359(\s|-)[2]\1\d{3}\1\d{4}\b";
  16.            
  17.  
  18.             Regex pattern = new Regex(rg);
  19.  
  20.             string phones = Console.ReadLine();
  21.  
  22.             var phoneMatch = Regex.Matches(phones, rg);
  23.  
  24.             string[] matchedPhones = phoneMatch.Cast<Match>().Select(x => x.Value.Trim()).ToArray();
  25.  
  26.             Console.Write(string.Join(", ", matchedPhones));
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment