Advertisement
GerganaTsirkova

Matches dates

Feb 23rd, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace MatchDates
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.             string pattern = @"\b(?<day>\d{2})([.\/-]{1})(?<month>[a-zA-Z]{3})\1(?<year>\d{4})";
  13.             var dates = Regex.Matches(input, pattern);
  14.             foreach(Match item in dates)
  15.             {
  16.                 var day = item.Groups["day"].Value;
  17.                 var month = item.Groups["month"].Value;
  18.                 var year = item.Groups["year"].Value;
  19.                 Console.WriteLine($"Day: {day},Month: {month},Year: {year}");
  20.             }
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement