Advertisement
Aborigenius

MatchDates

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