I have written this very straight forward regex code
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);
}
}
}
}
The Output for the following is:
2019-05-07
11:50:28
Ayush Singhania
Level 1
1001
ayush.power
........... (The Last Line is Blank)
Everything is working fine excel for the last group - "Message"
It does not print anything. Can anyone suggest why is it so?
Also i think my regex pattern is correct. Check it here https://regex101.com/r/ysawNT/1