Advertisement
Guest User

MatchPhoneNumber

a guest
Nov 24th, 2019
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace MatchPhoneNummber
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string pattern = @"(?<=^|\s)\+\d{3}(?<delimiter>[-|\s])2\k<delimiter>\d{3}\k<delimiter>\d{4}\b";
  12. var phones = Console.ReadLine();
  13.  
  14. var totalMatches = Regex.Matches(phones, pattern);
  15.  
  16. var MatchesPhones = totalMatches
  17. .Cast<Match>()
  18. .Select(a => a.Value.Trim())
  19. .ToArray();
  20.  
  21.  
  22.  
  23. Console.WriteLine(string.Join(", ",totalMatches));
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement