Advertisement
didito33

Match Phone Number

Nov 26th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Linq;
  4. namespace Lekciq_02.Match_Phone_Number
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input = Console.ReadLine();
  11.             Regex regex = new Regex(@"(?<start>^|[\s])(?<country>\+359)(?<separator>[\- ])(?<number>2)\k<separator>[0-9]{3}\k<separator>[0-8]{4}\b");
  12.             MatchCollection matches = regex.Matches(input);
  13.  
  14.             var array = matches.Cast<Match>().Select(a => a.Value.Trim()).ToArray();
  15.  
  16.             Console.WriteLine(string.Join(", ", array));
  17.         }
  18.     }
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement