日期:2014-05-17 浏览次数:20559 次
string tempStr = File.ReadAllText(@"C:\Users\myx\Desktop\Test.txt", Encoding.GetEncoding("GB2312"));//读取txt
var _list = Regex.Matches(tempStr, @"(?i)(?<=(?<Date>\d{4}[/-]\d{1,2}[/-]\d{1,2})[^\d]*?(?<Time>\d+[::]\d+)(?:(?!\d{4}[/-])[\s\S]*?))\d+?\.\d+?\.\d+?\.\d+?(?:[:]\d+)\s+?(?<IP>\d+?\.\d+?\.\d+?\.\d+)[:]?(?<Num>\d+)?").Cast<Match>().Select(a => new
{
DateTime=a.Groups["Date"].Value+" "+a.Groups["Time"].Value,
IP=a.Groups["IP"].Value,
Num=a.Groups["Num"].Value
}).ToList();
/*
* + [0] { DateTime = "2013/06/08 15:36", IP = "11.19.136.16", Num = "29119" } <Anonymous Type>
+ [1] { DateTime = "2013/06/08 15:36", IP = "12.19.111.2", Num = "1196" } <Anonymous Type>
+ [2] { DateTime = "2013/06/08 15:36", IP = "18.87.77.7", Num = "60100" } <Anonymous Type>
*/