using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(?:
# Apr - Dec, 1999
(?:(?:(?:0?\d|[12]\d|3[01])\/(?:0?[578]|1[02]))|(?:(?:0?\d|[12]\d|30)\/(?:0?[469]|11))|(?:(?:0?\d|1\d|2[0-8])\/0?2))\/1999
|
# 2000 - 2003
(?:(?:(?:0?\d|[12]\d|3[01])\/(?:0?[13578]|1[02]))|(?:(?:0?\d|[12]\d|30)\/(?:0?[469]|11))|(?:(?:0?\d|1\d|2[0-8])\/0?2))\/200[0-3]
|
# Jan - Mar, 2004
(?:(?:(?:0?\d|[12]\d|3[01])\/(?:0?[13]))|(?:(?:0?\d|1\d|2[0-8])\/0?2))\/2004
|
# Leap years!
29\/0?2\/200[04]
)$";
string input = @"01/04/1999
31/03/1999
29/02/2000
30/02/2000
28/2/2001
29/2/2001
30/4/2002
31/4/2002
31/1/2003
32/1/2003
31/3/2004
01/4/2004";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace;
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