using System; using System.Text.RegularExpressions; public class Test { public static void Main() { var str = "ID: JK546|Guitar: 0|Piano: 1|Violin: 0|Expiry: Aug14,2021"; string pattern = @"(ID: \w+\|)(\w+: \d+\|)+(Expiry: \w+,\d+)"; Match m = Regex.Match(str, pattern); foreach(Capture c in m.Groups[2].Captures) { Console.WriteLine(m.Groups[1].Value + c.Value + m.Groups[3].Value); } } }