Advertisement
Aborigenius

Match Phone Number

Aug 24th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 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. namespace RegEx
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string pattern = @"[+359]{4}([-| ])[2]\1[0-9]{3}[-| ][0-9]{4}\b";
  15.             //I hate you Regex
  16.  
  17.             var phones = Console.ReadLine();
  18.  
  19.             var phoneMatches = Regex.Matches(phones, pattern);
  20.  
  21.             var matchedPhones = phoneMatches.Cast<Match>().Select(n => n.Value.Trim()).ToArray();
  22.  
  23.             Console.WriteLine(string.Join(", ", matchedPhones));
  24.         }
  25.     }
  26. }
  27. //\b(?>\p{Lu}\p{M}*)(?>\p{L}\p{M}*)*(?:\s+(?>\p{Lu}\p{M}*)(?>\p{L}\p{M}*)*){0,2}\b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement