0
我需要找出所有字符串匹配大字符串緩衝區中的特定模式。如何找到具有特定模式的匹配字符串
例如,我有一個像
"2014:11:12 13:30:05 Tested for ABCD at 12:30 2014:11:12 13:31:05 Tested for ABBB at 12:31 2014:11:12 13:32:05 Tested for ABCC at 12:32"
一個字符串,我想有一個像這樣的輸出:
2014:11:12 13:30:05 ABCD 12:30
2014:11:12 13:31:05 ABBB 12:31
2014:11:12 13:32:05 ABCC 12:32
我曾嘗試用類似這樣的代碼:
string data = "2014:11:12 13:30:05 Tested for ABCD at 12:30 2014:11:12 13:31:05 Tested for ABBB at 12:31 2014:11:12 13:32:05 Tested for ABCC at 12:32";
MatchCollection matches = Regex.Matches("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} Tested for [?]{4} at [0-9]{2}:[0-9]{2}");
/* But matches.count is always 0 here, looks like the pattern [?]{4} not work */
foreach (Match match in matches)
{
string temp = match.Value;
Match dateTime = Regex.Match(temp, "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}");
Match Org = Regex.Match(temp, "Tested for [?]{4}").Value, "[?]{4}");
Match processingTime = Regex.Match(temp, "at [0-9]{2}:[0-9]{2}").Value, "[0-9]{2}:[0-9]{2}");
/* then parse the field datetime, Org and processingTime and write to console */
}
你能告訴我們你試過的東西,告訴我們什麼沒有奏效嗎?也許那麼我們可以幫助你弄清楚什麼不起作用。 –