Advertisement
YavorGrancharov

Match_Dates(regex_80%)

Aug 22nd, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Match_Dates
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string pattern = @"([0-9]{2}[\/][A-Z]{1}[a-z]{2}[\/][0-9]{4})|([0-9]{2}[\-][A-Z]{1}[a-z]{2}[\-][0-9]{4})|([0-9]{2}[\.][A-Z]{1}[a-z]{2}[\.][0-9]{4})";
  13.  
  14.             string input = Console.ReadLine();
  15.  
  16.             MatchCollection days = Regex.Matches(input, pattern);
  17.  
  18.             Dictionary<string, Dictionary<string, string>> store =
  19.                 new Dictionary<string, Dictionary<string, string>>();
  20.             foreach (Match data in days)
  21.             {
  22.                 string[] tokens = data.Value.Split('/', '.', '-');
  23.                 string day = tokens[0];
  24.                 string month = tokens[1];
  25.                 string year = tokens[2];
  26.  
  27.                 if (!store.ContainsKey(day))
  28.                 {
  29.                     store.Add(day, new Dictionary<string, string>());
  30.                 }
  31.                 store[day][month] = year;
  32.             }
  33.             foreach (var data in store)
  34.             {
  35.                 Console.Write($"Day: {data.Key}, ");
  36.                 Dictionary<string, string> second = data.Value;
  37.                 foreach (var entry in second)
  38.                 {
  39.                     Console.Write($"Month: {entry.Key}, Year: {entry.Value}");
  40.                 }
  41.                 Console.WriteLine();
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement