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 = "ISNULL(d.Type, 0), d.Subject + ', ' + d.Name, d.Something,array_position(ARRAY['f', 'p', 'i', 'a']::varchar[], x_field), test";
  12. var pattern = @"(\([^()]*\)|'[^']*')|\s*,";
  13. var result = Regex.Replace(text, pattern, m => m.Groups[1].Success ? m.Value : " DESC,");
  14. Console.WriteLine(result);
  15. }
  16. }
Success #stdin #stdout 0.06s 27520KB
stdin
Standard input is empty
stdout
ISNULL(d.Type, 0) DESC, d.Subject + ', ' + d.Name DESC, d.Something DESC,array_position(ARRAY['f', 'p', 'i', 'a']::varchar[], x_field) DESC, test