I am parsing text and if I encounter a time, I want to split the string. Here is an example:
At 12:30AM I got up. At 11:30PM I went to bed.
My code :
string time = @"[0-9]{2}:[0-9]{2}(A|P)M";
string test = "At 12:30AM I got up. At 11:30PM I went to bed.";
string[] result = Regex.Split(test, time);
foreach(string element in result)
{
Console.WriteLine(element);
}
What I need to get:
At 12:30AM
I got up. At 11:30PM
I went to bed.
What I get:
At
A
I got up. At
P
I went to bed.
All that is left of the times are either A or P.