RegEx for a date format
- by Ivan
Say I have a string like this:
07-MAY-07 Hello World 07-MAY-07 Hello Again
So the pattern is, DD-MMM-YY, where MMM is the three letter format for a month. What Regular Expression will break up this string into:
07-MAY-07 Hello World
07-MAY-07 Hello Again
Using Jason's code below modified for C#,
string input = @"07-MAY-07 Hello World 07-MAY-07 Hello Again";
string pattern = @"(\d{2}-[A-Z]{3}-\d{2}\s)(\D*|\s)";
string[] results = Regex.Split(input, pattern);
results.Dump();
Console.WriteLine("Length = {0}", results.Count());
foreach (string split in results)
{
Console.WriteLine("'{0}'", split);
Console.WriteLine();
}
I get embedded blank lines?
Length = 7
''
'07-MAY-07 '
'Hello World '
''
'07-MAY-07 '
'Hello Again'
''
I don't even understand why I am getting the blank lines...?