Advertisement
martinvalchev

Match_Dates

Feb 21st, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 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 Match_Dates
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string pattern = @"\b(?<day>\d{2})(-|.|\/)(?<month>[A-Z][a-z]{2})\1(?<year>\d{4})\b";
  15.  
  16.             string dates = Console.ReadLine();
  17.  
  18.             var regex = Regex.Matches(dates, pattern);
  19.  
  20.             foreach (Match date in regex)
  21.             {
  22.                 var day = date.Groups["day"].Value;
  23.                 var month = date.Groups["month"].Value;
  24.                 var years = date.Groups["year"].Value;
  25.  
  26.                 Console.WriteLine($"Day: {day}, Month: {month}, Year: {years}");
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement