fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace SO13389560Balancing
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string s = "~(a b (c) d (e f (g) h) i) j (k (l (m) n) p) q";
  14. string pattern = @"(?<=~[(](?:[^()]*|(?<Depth>[(])|(?<-Depth>[)]))*)[a-z]";
  15.  
  16.  
  17. s = Regex.Replace(s, pattern, "!");
  18.  
  19. Console.WriteLine(s);
  20. //Console.ReadKey();
  21. }
  22. }
  23. }
  24.  
Success #stdin #stdout 0.07s 37384KB
stdin
Standard input is empty
stdout
~(! ! (!) d (! ! (!) h) i) j (k (l (!) n) p) q