using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"[0-9]{2}\/[0-9]{2}\/[0-9]{4}";
string input = @"Valid dates:
01/04/2020
20/01/2019
25/12/1950
30/07/2021
31/08/1919
01/01/1729
10/05/2000
15/10/2049
Invalid dates:
001/04/1900
01/004/1900
90/04/1900
33/04/1900
01/13/1900
01/04/19000
00/04/1900
01/00/1900
1/4/00
1/04/1900
10/4/1900
10/04/00
///
/04/1900
01//1900
01/04/
01/04/1900
This is the date: 01/04/1900
01.04.1900
01-04-1900
";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx