1

在我的日志文件中,字段“appGUID”主要有 3 种类型的值,即“wx”、“null”和包含字符和数字混合的值。我想以这样一种方式过滤掉内容,即包含“wx”和“null”的所有 appGUID 值都存储在一个空的新字符串中,并且包含字符和数字混合的 appGUID 值被丢弃。我无法弄清楚它的正则表达式模式。请帮忙。

我的日志文件格式为:

INFO [com.adobe.watson.vo.BugServices] WX 编辑错误:3494430 服务器:yukon.corp.adobe.com 用户:xinche appGUID:null INFO [com.adobe.watson.vo.BugServices] WX 编辑错误:3494430 服务器: yukon.corp.adobe.com 用户:xinche appGUID: null INFO [com.adobe.watson.vo.BugServices] WX 编辑错误: 3419432 服务器: yukon.corp.adobe.com 用户:prerelease appGUID: fcdd2153-bbdf INFO [ com.adobe.watson.vo.BugServices] WX 编辑错误:3419432 服务器:yukon.corp.adobe.com 用户:prerelease appGUID:fcdd2153-bbdf INFO [com.adobe.watson.vo.BugServices] WX 编辑错误:3494430 服务器: yukon.corp.adobe.com 用户:xinche appGUID: wx INFO [com.adobe.watson.vo.BugServices] WX 编辑错误: 3494430 服务器: yukon.corp.adobe.com 用户:xinche appGUID: wx INFO [com. adobe.watson.vo.BugServices] WX 编辑错误:3494430 服务器:yukon.corp.adobe.com 用户:xinche appGUID:null INFO [com.adobe.watson.vo.BugServices] WX 编辑错误:3494430 服务器:yukon.corp.adobe.com 用户:xinche appGUID:null INFO [com.adobe.watson.vo.BugServices] WX 编辑错误:3419432服务器:yukon.corp.adobe.com 用户:prerelease appGUID:fcdd2153-bbdf INFO [com.adobe.watson.vo.BugServices] WX 编辑错误:3419432 服务器:yukon.corp.adobe.com 用户:prerelease appGUID:fcdd2153- bbdf

我的代码在这里:

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);
}
4

1 回答 1

0

您可以使用appGUID: (?<value>wx|null)

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: (?<value>wx|null)");
MatchCollection matches = regex.Matches(x);
foreach (Match match in matches)
{
    var user = match.Groups["value"].Value;
    if (!users.Contains(user))
        users.Add(user);
于 2013-03-07T11:38:06.170 回答