using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var s = "My test string is ##[FirstVal][SecondVal]##"; var myvalues = Regex.Matches(s, @"##(?:\[([^][]*)])+##") .Cast() .SelectMany(m => m.Groups[1].Captures .Cast() .Select(t => t.Value)); Console.WriteLine(string.Join(", ", myvalues)); } }