fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var text = @"\firstcommand{\secondcommand{nestedcontent} outercontent}";
  12. var pattern = @"\\(\w+)\{([^{}]*)}";
  13. var prev = string.Empty;
  14. do {
  15. prev = text;
  16. text = Regex.Replace(text, pattern, "<$1>$2</$1>");
  17. } while (prev != text);
  18. Console.WriteLine(text);
  19. }
  20. }
Success #stdin #stdout 0.08s 29432KB
stdin
Standard input is empty
stdout
<firstcommand><secondcommand>nestedcontent</secondcommand> outercontent</firstcommand>