过滤值我希望我的计划,放弃所有这些线路中,“APPGUID”的值是“WX”或“空”使用正则表达式在C#
我怎样才能做到这一点使用正则表达式。在此之后,它应该返回“WX Edit Bug”的唯一值。我试过但看起来像我的代码中的一些错误。
我无法弄清楚它的正则表达式模式。请帮忙。
我的日志文件格式:
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: 3494430 Server: yukon.corp.adobe.com User:xinche appGUID: wx INFO [com.adobe.watson.vo.BugServices] WX Edit Bug: 3494430 Server: yukon.corp.adobe.com User:xinche appGUID: wx 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
我的代码是在这里:
IEnumerable<string> textLines
= Directory.GetFiles(@"C:\Users\karansha\Desktop\Dummy\", "*.*")
.Select(filePath => File.ReadLines(filePath))
.SelectMany(line => line);
string x = string.Join(",", textLines);
Regex regex = new Regex(@"(.*)?(wx|null)\b");
var newString = regex.Replace(x, String.Empty);
string discard = string.Join(",", newString);
List<string> users = new List<string>();
Regex regex1 = new Regex(@"WX Edit Bug:\s*(?<value>.*?)\s+Server");
MatchCollection matches1 = regex1.Matches(discard);
foreach (Match match in matches1)
{
var Editbug = match.Groups["value"].Value;
if (!users.Contains(Editbug)) users.Add(Editbug);
}
int WX_Edit = users.Count;
只是为了CLAR你能展示预期的产出吗? – 2013-03-07 15:22:05
http://stackoverflow.com/a/15264675/470005 – 2013-03-07 15:24:05