我正在解析文本,如果遇到时间,我想拆分字符串。这是一个例子:
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。