c# - 为什么它不打印 C# 中的最后一个正则表达式组
问题描述
我写了这个非常直接的正则表达式代码
using System;
using System.Text.RegularExpressions;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string lines = "2019-05-07 11:50:28, INFO Ayush Singhania, Level 1, EID: 1001, UID: ayush.power, Message: Create a Job";
Regex pattern = new Regex(@"(?<Date>.*?\s)(?<Time>.*?), INFO(?<Name>.*?),(?<Level>.*?), EID: (?<EID>.*?), UID: (?<UID>.*?), Message: (?<Message>.*?)");
MatchCollection myMatchCollection = pattern.Matches(lines);
foreach (Match myMatch in myMatchCollection)
{
var Date = myMatch.Groups["Date"].Value;
var Time = myMatch.Groups["Time"].Value;
var Name = myMatch.Groups["Name"].Value;
var Level = myMatch.Groups["Level"].Value;
var EID = myMatch.Groups["EID"].Value;
var UID = myMatch.Groups["UID"].Value;
var Message = myMatch.Groups["Message"].Value;
Console.Out.WriteLine(Date);
Console.Out.WriteLine(Time);
Console.Out.WriteLine(Name);
Console.Out.WriteLine(Level);
Console.Out.WriteLine(EID);
Console.Out.WriteLine(UID);
Console.Out.WriteLine(Message);
}
}
}
}
以下的输出是:
2019-05-07
11:50:28
Ayush Singhania
1 级
1001
ayush.power
......(最后一行为空白)
最后一组的一切都很好 - “消息”
它不打印任何东西。谁能建议为什么会这样?
我也认为我的正则表达式模式是正确的。在这里查看https://regex101.com/r/ysawNT/1
解决方案
推荐阅读
- javascript - 启用了严格的 mime 类型检查,拒绝执行来自 ' 的脚本
' 它的 mime 类型 ('text/plain') 是不可执行的,并且 - keras - 翻转时间轴并应用 TimeDistributed RNN 来保留空间维度
- r - 如何为每个模拟运行循环并使用这些值创建一个新向量?
- ssl - WebRtc:无法为传输设置 SSL 角色
- linux - 是否必须使用 Cloud9 iDE 与 AWS 交互?
- c++ - 向量下标超出范围。比较向量的元素
- python - 如何在 python 中使用 GTK3 检查窗口是否存在并可能更新其中的数据?
- python - Python:根据列表不完整序列查找单词/字符串的基础序列
- angular - Angular - 如何在 NgFor 中创建动态模板变量
- java - 连接到Android设备时如何获取WIFI提供商名称