Mike_Goodman92

Untitled

Nov 4th, 2017
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _04.Match_Dates
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. //var pattern = @"\b(\d{2})([.\/-])([A-Z][a-z]{2})\2(\d{4})\b";
  13. //// \b(?< day >\d{ 2})([.\/ -])(?< month >[A - Z][a - z]{ 2})\2(?< year >\d{ 4})\b
  14. //string datesString = Console.ReadLine();
  15.  
  16. //MatchCollection dates = Regex.Matches(datesString, pattern);
  17.  
  18. //foreach (Match date in dates)
  19. //{
  20. // string day = date.Groups[1].Value;
  21. // string month = date.Groups[3].Value;
  22. // string year = date.Groups[4].Value;
  23.  
  24. // Console.WriteLine($"Day: {day}, Month: {month}, Year: {year}");
  25. //}
  26.  
  27.  
  28. var pattern = @"\b(?<day>\d{2})([.\/-])(?<month>[A-Z][a-z]{2})\1(?<year>\d{4})\b";
  29.  
  30. // var pattern = @"\b(?<day>\d{2})([.\/-])(?<month>[A-Z][a-z]{2}) \2 /* трябва да е \1 a не \2 */ (?<year>\d{4})\b";
  31.  
  32. // Since RegEx works differently across different languages, before we continue
  33. //, we’re going to set our backreference from \2 to \1.
  34. //This is because C# backreferences don’t count named capture groups for backreferences.
  35. //So, change it before we continue.
  36.  
  37. string datesString = Console.ReadLine();
  38.  
  39. MatchCollection dates = Regex.Matches(datesString, pattern);
  40.  
  41. foreach (Match date in dates)
  42. {
  43. string day = date.Groups["day"].Value;
  44. string month = date.Groups["month"].Value;
  45. string year = date.Groups["year"].Value;
  46.  
  47. Console.WriteLine($"Day: {day}, Month: {month}, Year: {year}");
  48. }
  49.  
  50.  
  51.  
  52. }
  53. }
  54. }
Add Comment
Please, Sign In to add comment