Advertisement
YavorGrancharov

Match_Phone_Number

Aug 22nd, 2017
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace Match_Phone_Number
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             //string pattern = @"( ?\+359 2 \d{3} \d{4})|(\+ ?359-2-\d{3}-\d{4})+\b";
  12.             string pattern = @"( ?\+359 2 \d{3} \d{4})|(\+ ?359-2-\d{3}-\d{4})+\b|(\+ ?359\/2\/\d{3}\/\d{4})+\b";
  13.  
  14.             string input = Console.ReadLine();
  15.  
  16.             string result = string.Empty;
  17.             MatchCollection phones = Regex.Matches(input, pattern);
  18.  
  19.             foreach (Match phone in phones)
  20.             {
  21.                 result += phone.Value + ", ";                
  22.             }
  23.             Console.Write(result.TrimEnd(' ', ','));
  24.             Console.WriteLine();
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement