fork(2) download
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Test
  6. {
  7. static string regExp = "(((?<x>(?=[,\\r\\n]+))|\"(?<x>([^\"]|\"\")+)\"|(?<x>[^,\\r\\n]+)),?)";
  8.  
  9. public static void Main()
  10. {
  11. var line = ",\"clean text\",\"with,embedded,commas.\",\"with\"\"embedded\"\"double\"\"quotes\",,\"6.1\",";
  12.  
  13. var vals= (from Match m in Regex.Matches(line, regExp, RegexOptions.ExplicitCapture)
  14. select m.Groups[1].Value).ToArray();
  15.  
  16. Console.WriteLine("<start>");
  17. foreach(var s in vals)
  18. Console.WriteLine(s);
  19. Console.WriteLine("<end>");
  20. }
  21. }
Success #stdin #stdout 0.08s 34272KB
stdin
Standard input is empty
stdout
<start>

clean text
with,embedded,commas.
with""embedded""double""quotes

6.1
<end>