C# 使用正则表达式过滤C中的值

C# 使用正则表达式过滤C中的值,c#,C#,我希望我的程序放弃所有appGUID值为wx或null的行 如何使用regex实现这一点。在此之后,它应该返回WX Edit Bug的唯一值。我试过了,但代码中似乎有一些bug 我不知道这是正则表达式模式。请帮忙 我的日志文件的格式为: 信息[com.adobe.watson.vo.BugServices]WX编辑错误:3494430服务器: 育空公司adobe.com用户:xinche appGUID:null信息 [com.adobe.watson.vo.BugServices]WX编辑错误

我希望我的程序放弃所有appGUID值为wx或null的行

如何使用regex实现这一点。在此之后,它应该返回WX Edit Bug的唯一值。我试过了,但代码中似乎有一些bug

我不知道这是正则表达式模式。请帮忙

我的日志文件的格式为:

信息[com.adobe.watson.vo.BugServices]WX编辑错误:3494430服务器: 育空公司adobe.com用户:xinche appGUID:null信息 [com.adobe.watson.vo.BugServices]WX编辑错误:3494430服务器: 育空公司adobe.com用户:xinche appGUID:null信息 [com.adobe.watson.vo.BugServices]WX编辑错误:3419432服务器: 育空公司adobe.com用户:预发布appGUID:fcdd2153 bbdf信息 [com.adobe.watson.vo.BugServices]WX编辑错误:3419432服务器: 育空公司adobe.com用户:预发布appGUID:fcdd2153 bbdf信息 [com.adobe.watson.vo.BugServices]WX编辑错误:3494430服务器: 育空公司adobe.com用户:xinche appGUID:wx信息 [com.adobe.watson.vo.BugServices]WX编辑错误:3494430服务器: 育空公司adobe.com用户:xinche appGUID:wx信息 [com.adobe.watson.vo.BugServices]WX编辑错误:3494430服务器: 育空公司adobe.com用户:xinche appGUID:null信息 [com.adobe.watson.vo.BugServices]WX编辑错误:3494430服务器: 育空公司adobe.com用户:xinche appGUID:null信息 [com.adobe.watson.vo.BugServices]WX编辑错误:3419432服务器: 育空公司adobe.com用户:预发布appGUID:fcdd2153 bbdf信息 [com.adobe.watson.vo.BugServices]WX编辑错误:3419432服务器: yukon.corp.adobe.com用户:预发布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;

使用您提供的代码,并假设查询的第一部分工作正常,您可以尝试使用未测试的Where子句:


为了清楚起见,您能显示预期的输出吗?bool不包含to list的定义。它给出了一个错误:bool不包含to list的定义。是的,它起作用了。你是天才。现在,如果我想让它放弃appGUID:null和appGUID:wx的行,并打印appGUID的值不是null和wx的行,该怎么办。谢谢。
IEnumerable<string> textLines
    = Directory.GetFiles(@"C:\Users\karansha\Desktop\Dummy\", "*.*")
               .Select(filePath => File.ReadLines(filePath))
               .SelectMany(line => line)
               .Where(line => line.Contains("appGUID: null") || line.Contains("appGUID: wx"))
               .ToList();