テキストを解析していますが、時間が発生した場合は、文字列を分割したいと考えています。次に例を示します。
At 12:30AM I got up. At 11:30PM I went to bed.
私のコード:
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);
}
私が得る必要があるもの:
At 12:30AM
I got up. At 11:30PM
I went to bed.
私が得るもの:
At
A
I got up. At
P
I went to bed.
残っているのはAかPのどちらかだけです。