如何创建正则表达式以从日志文件中可用的以下行中获取特定(bug.updateBug)字符串,如下所示:WX 编辑错误:3550704 服务器:服务器名用户:testuser appGUID:appguidvalue 经过时间:624 毫秒方法:bug.updateBug 日期: 2013 年 5 月 1 日星期三 09:38:01 PDT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApplication59
{
class Program
{
static void Main(string[] args)
{
IEnumerable<string> textLines
= Directory.GetFiles(@"C:\testlocation\", "*.*")
.Select(filePath => File.ReadLines(filePath))
.SelectMany(line => line);
List<string> users = new List<string>();
Regex r = new Regex("^.*WX\\sADVSearch(.*)50\\]$");
foreach (string Line in textLines)
{
if (r.IsMatch(Line))
{
users.Add(Line);
}
}
string[] textLines1 = new List<string>(users).ToArray();
int countlines = textLines1.Count();
Console.WriteLine("WX_ADVSearch=" + countlines);
// keep screen from going away
// when run from VS.NET
Console.ReadLine();
}
}
}