我希望我的程序丢弃所有值为appGUID
orwx
的行null
。如何使用正则表达式实现这一目标?
我无法弄清楚它的正则表达式模式。请帮忙。
我的日志文件格式为:
INFO [com.adobe.watson.vo.BugServices] WX Edit Bug: 3494430 Server: yukon.corp.adobe.com User:xinche appGUID: null
INFO [com.adobe.watson.vo.BugServices] WX Edit Bug: 3494430 Server: yukon.corp.adobe.com User:xinche appGUID: null
INFO [com.adobe.watson.vo.BugServices] WX Edit Bug: 3494430 Server: yukon.corp.adobe.com User:xinche appGUID: null
INFO [com.adobe.watson.vo.BugServices] WX Edit Bug: 3419432 Server: yukon.corp.adobe.com User:prerelease appGUID: fcdd2153-bbdf
INFO [com.adobe.watson.vo.BugServices] WX Edit Bug: 3419432 Server: yukon.corp.adobe.com User:prerelease appGUID: fcdd2153-bbdf
INFO [com.adobe.watson.vo.BugServices] WX Edit Bug: 3419422 Server: yukon.corp.adobe.com User:prerelease appGUID: fcdd2153-bbdf
INFO [com.adobe.watson.vo.BugServices] WX Edit Bug: 3419442 Server: yukon.corp.adobe.com User:prerelease appGUID: fcdd2153-bbdf
INFO [com.adobe.watson.vo.BugServices] WX New Bug: 3494441 Server: yukon.corp.adobe.com User:bey81694 appGUID: wx
INFO [com.adobe.watson.vo.BugServices] WX New Bug: 3494441 Server: yukon.corp.adobe.com User:bey81694 appGUID: wx
INFO [com.adobe.watson.vo.BugServices] WX New Bug: 3494441 Server: yukon.corp.adobe.com User:bey81694 appGUID: wx
我的代码在这里:
StreamReader reader = new StreamReader(@"C:\Users\karansha\Desktop\Karan Logs\20110717.txt");
string x = reader.ReadToEnd();
List<string> users = new List<string>();
Regex regex = new Regex(@"appGUID:\s*(?<value>.*?)\s");
MatchCollection matches = regex.Matches(x);
foreach (Match match in matches)
{
var user = match.Groups["value"].Value;
if (!users.Contains(user)) users.Add(user);
}