Militsa

08. Match Dates

Nov 29th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _08.Match_Dates
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var regex = @"\b(?<day>\d{2})([-.\/])(?<month>[A-Z][a-z]{2})\1(?<year>\d{4})\b";
  14.             var input = Console.ReadLine();
  15.             var result = Regex.Matches(input,regex);
  16.  
  17.             foreach (Match date in result)
  18.             {
  19.                 var day = date.Groups["day"].Value;
  20.                 var month = date.Groups["month"].Value;
  21.                 var year = date.Groups["year"].Value;
  22.  
  23.                 Console.WriteLine("Day: {0}, Month: {1}, Year: {2}",day,month,year);
  24.             }
  25.         }
  26.     }
  27. }
Add Comment
Please, Sign In to add comment