0

i used many examples found here and i can't figure out why this is not working. i want to search a sentence to find anything matches dd.mm.yyyy:

string pattern = @"^\s*(3[01]|[12][0-9]|0?[1-9])\.(1[012]|0?[1-9])\.((?:19|20)\d{2})\s*$";
    Regex rgx = new Regex(pattern);
    string sentence = "4.11.2020 HELLO WORLD";
    foreach (Match match in rgx.Matches(sentence))
        Console.WriteLine("Found '{0}' at position {1}",
                          match.Value, match.Index);

when i remove "hello world" it works. but i have seen examples of this working with other chars after or before the date. thanks for any ideas what I did wrong.

elitzur e
  • 67
  • 9

0 Answers0