fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var text = "{token1:param1}stuff{token2}more stuff{token3:param3}";
  11. var pattern = @"\{(?<key>[^:}]*)(?::(?<value>[^}]*))?}";
  12. var matches = Regex.Matches(text, pattern);
  13. foreach (Match m in matches)
  14. {
  15. Console.WriteLine(m.Value);
  16. Console.WriteLine(m.Groups["key"].Value);
  17. Console.WriteLine(m.Groups["value"].Value);
  18. }
  19. }
  20.  
  21. }
Success #stdin #stdout 0.06s 27376KB
stdin
Standard input is empty
stdout
{token1:param1}
token1
param1
{token2}
token2

{token3:param3}
token3
param3