using System;
using System.Linq;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
var matches = Regex.Matches("Test {Token1} {Token 2}", @"{([^{}]*)");
var results = matches.Cast<Match>().Select(m => m.Groups[1].Value).Distinct().ToList();
Console.WriteLine(String.Join(", ", results));
matches = Regex.Matches("Test {Token1} {Token {2}}", @"{((?>[^{}]+|{(?<c>)|}(?<-c>))*(?(c)(?!)))");
results = matches.Cast<Match>().Select(m => m.Groups[1].Value).Distinct().ToList();
Console.WriteLine(String.Join(", ", results));
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLlRleHQuUmVndWxhckV4cHJlc3Npb25zOwpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJdmFyIG1hdGNoZXMgPSBSZWdleC5NYXRjaGVzKCJUZXN0IHtUb2tlbjF9IHtUb2tlbiAyfSIsIEAieyhbXnt9XSopIik7CgkJdmFyIHJlc3VsdHMgPSBtYXRjaGVzLkNhc3Q8TWF0Y2g+KCkuU2VsZWN0KG0gPT4gbS5Hcm91cHNbMV0uVmFsdWUpLkRpc3RpbmN0KCkuVG9MaXN0KCk7CgkJQ29uc29sZS5Xcml0ZUxpbmUoU3RyaW5nLkpvaW4oIiwgIiwgcmVzdWx0cykpOwoJCW1hdGNoZXMgPSBSZWdleC5NYXRjaGVzKCJUZXN0IHtUb2tlbjF9IHtUb2tlbiB7Mn19IiwgQCJ7KCg/Pltee31dK3x7KD88Yz4pfH0oPzwtYz4pKSooPyhjKSg/ISkpKSIpOwoJCXJlc3VsdHMgPSBtYXRjaGVzLkNhc3Q8TWF0Y2g+KCkuU2VsZWN0KG0gPT4gbS5Hcm91cHNbMV0uVmFsdWUpLkRpc3RpbmN0KCkuVG9MaXN0KCk7CgkJQ29uc29sZS5Xcml0ZUxpbmUoU3RyaW5nLkpvaW4oIiwgIiwgcmVzdWx0cykpOwoJfQp9