Advertisement
Spocoman

02. Match Phone Number

Apr 18th, 2023 (edited)
1,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace MatchPhoneNumber
  6. {
  7.     internal class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string numbers = Console.ReadLine();
  12.  
  13.             Regex pattern = new Regex(@" ?\+359([- ])2(\1)\d{3}(\1)\d{4}\b");
  14.  
  15.             MatchCollection matchedNumbers = pattern.Matches(numbers);
  16.  
  17.             Console.Write(string.Join(", ", matchedNumbers.Select(x => x.Value.Trim())));
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement