using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"((?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|(Nov|Dec)(?:ember)?)(\s)([1,2][\d]|[1-9]|30|31)(\s))?(\b[\d]|10|11|12):[0-5][0-9]\s(AM|PM)";
string input = @"March 9 12:31 AM and March 10 7:30 AM
March 11 7:30 AM and March 12 10:30 AM
Mar 31 9:00 PM and Apr 1 12:39 AM
March 31 10:11 PM and April 1 5:23 AM
7:45 PM and 10:30 PM
May 3 4:41 PM PDT and May 4 12:19 AM PDT
March 31 10:71 PM and April 1 5:23 AM
27:45 PM and 10:80 PM
May 3 4:41 PM PDT and May 41 12:19 AM PDT";
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