using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?>[\w]*)\s(?'LogType'[\w]*)\:(?'LogVersion'[\w]*)\|(?'SystemOrigin'[\w]*)\|(?'Platform'[\w]*)\|(?'EventID'[\w]*)\|(?'EventName'[\w\s]*)\|(?>[\w\s]*)\|(?'Severity'[\w]*)\|(?>id=)(?'ID'[\w\-]*)\s(?>shost=)(?'SHOST'[\w\-]*)\scs1Label=(?'cs1Label'[\w\s]*)\s(?:cs1=|,\s)(?'Agent1'[\w.-]+)\s\(ip:\s(?'IP'[0-9.]+),\scomponent_id:\s(?'ComponentID'[\w.-]+)\)";
string input = @"SystemX CEF:0|SystemX|PlatformX|01|Agent Log Event|Agent Log Event|high|id=12xy-12xy-12xy-12xy-12xy shost=xy-aggregator-10-10-10-10 cs1Label=Affected Agents cs1=123.abc.com (ip: 10.0.0.1, component_id: x), 345.abc.com (ip: 10.0.0.2, component_id: y) msg=KO modules downloader failed with error code (202)";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx