Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用正则表达式根据C sharp中字段的值打印所需的行?_C# - Fatal编程技术网

C# 使用正则表达式根据C sharp中字段的值打印所需的行?

C# 使用正则表达式根据C sharp中字段的值打印所需的行?,c#,C#,在我的日志文件中,字段“appGUID”主要有3种类型的值,即“wx”、“null”和包含字符和数字混合的值。我希望以这样一种方式过滤掉内容:所有包含“wx”和“null”的appGUID值都存储在一个空的新字符串中,而包含字符和数字混合的appGUID值都将被丢弃。 我不知道这是正则表达式模式。请帮忙 我的日志文件的格式为: 信息[com.adobe.watson.vo.BugServices]WX编辑错误:3494430服务器: 育空公司adobe.com用户:xinche appGUID:

在我的日志文件中,字段“appGUID”主要有3种类型的值,即“wx”、“null”和包含字符和数字混合的值。我希望以这样一种方式过滤掉内容:所有包含“wx”和“null”的appGUID值都存储在一个空的新字符串中,而包含字符和数字混合的appGUID值都将被丢弃。 我不知道这是正则表达式模式。请帮忙

我的日志文件的格式为:

信息[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

我的代码在这里:

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);
}
StreamReader=newstreamreader(@“C:\Users\karansha\Desktop\Karan Logs\20110717.txt”);
字符串x=reader.ReadToEnd();
列表用户=新列表();
Regex Regex=new Regex(@“appGUID:\s*(?*?)\s”);
MatchCollection matches=regex.matches(x);
foreach(匹配中的匹配)
{
var user=match.Groups[“value”].value;
如果(!users.Contains(user))users.Add(user);
}

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

StreamReader=
新的StreamReader(@“C:\Users\karansha\Desktop\Karan Logs\20110717.txt”);
字符串x=reader.ReadToEnd();
列表用户=新列表();
Regex Regex=new Regex(@“appGUID:(?wx|null)”);
MatchCollection matches=regex.matches(x);
foreach(匹配中的匹配)
{
var user=match.Groups[“value”].value;
如果(!users.Contains(user))
用户。添加(用户);

您可以使用
appGUID:(?wx | null)
。但是您确定要捕获
appGUID
?还是要为
appGUID
的值为
null
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: (?<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);