using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
public class Test
{
public class Values
{
public string UnitType { get; set; }
public string UnitId { get; set; }
public string UnitTitle { get; set; }
public string Applicable { get; set; }
public string DeclineSender { get; set; }
public string DeclineReason { get; set; }
public string TriggeredByUser { get; set; }
public string DisplayReason { get; set; }
public string ModifiedBy { get; set; }
public override string ToString()
{
return $"UnitType: {UnitType}\nUnitId: {UnitId}\nUnitTitle: {UnitTitle}\nApplicable: {Applicable}\nDeclineSender: {DeclineSender}\nDeclineReason: {DeclineReason}\nTriggeredByUser: {TriggeredByUser}\nDisplayReason: {DisplayReason}\nModifiedBy: {ModifiedBy}";
}
}
public static void Main()
{
var pattern = @"\b(\w+(?:\s+\w+)*):\s*(.*?)(?=\s*;\w+(?:\s+\w+)*:|$)";
var text = "unitType:unit_failure;unitId:b7eb;unitTitle:L1-O VEN_ACC_SETTINGS>(30s)>EXCL(A);applicable:true;comment:Decline sender:SELLER;Decline reason:VEN_ACC_SETTINGS;triggered by user:495259708;Display reason: CON_FAILURE;modified by: log_res_mon";
text = Regex.Replace(text, @"(?<![^;])comment:(?=(?:unitType|unitId|unitTitle|applicable|Decline sender|Decline reason|triggered by user|Display reason|modified by):)", string.Empty, RegexOptions.IgnoreCase);
var vals = new List<Values>();
var v = new Values();
foreach (Match m in Regex.Matches(text, pattern))
{
if (m.Groups[1].Value == "unitType") v.UnitType=m.Groups[2].Value;
if (m.Groups[1].Value == "unitId") v.UnitId=m.Groups[2].Value;
if (m.Groups[1].Value == "unitTitle") v.UnitTitle=m.Groups[2].Value;
if (m.Groups[1].Value == "applicable") v.Applicable=m.Groups[2].Value;
if (m.Groups[1].Value == "Decline sender") v.DeclineSender=m.Groups[2].Value;
if (m.Groups[1].Value == "Decline reason") v.DeclineReason=m.Groups[2].Value;
if (m.Groups[1].Value == "triggered by user") v.TriggeredByUser=m.Groups[2].Value;
if (m.Groups[1].Value == "Display reason") v.DisplayReason=m.Groups[2].Value;
if (m.Groups[1].Value == "modified by") v.ModifiedBy=m.Groups[2].Value;
}
Console.WriteLine(v.ToString());
}
}