Sybatron

7.Match Dates

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