過濾值我希望我的計劃,放棄所有這些線路中,「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