Advertisement
Tsenkov

Untitled

Jul 29th, 2023
1,062
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 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.  * +359 2 222 2222,359-2-222-2222, +359/2/222/2222, +359-2 222 2222 +359 2-222-2222, +359-2-222-222, +359-2-222-22222 +359-2-222-2222
  9.  
  10.  */
  11. namespace _2.Match_Phone_Number
  12. {
  13.     internal class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             //string pattern = @"\+([\d]{3} [2]? [0-9]{3} [0-9]{4})|(\+[\d]{3}-[2]?-[0-9]{3}-\d{4}\b)";
  18.             string pattern = @"(\+359)(\-| )2(\2)\d{3}(\2)\d{4}\b";
  19.             string input = Console.ReadLine();
  20.            
  21.             var matches = Regex.Matches(input, pattern);
  22.            
  23.             var phonse = matches
  24.                 .Cast<Match>()
  25.                 .Select(a => a.Value.Trim())
  26.                 .ToArray();
  27.  
  28.             Console.WriteLine(string.Join(", ", phonse));
  29.         }
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement