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. string pattern = @"(?:""[^""]*""|\([^()]*\)|[^,])+";
  12. string input = "Selectroasted peanuts,Sugars (sugar, fancymolasses),Hydrogenatedvegetable oil (cottonseed and rapeseed oil),Salt.";
  13. foreach (Match m in Regex.Matches(input.TrimEnd(new[] {'!', '?', '.', '…'}), pattern))
  14. {
  15. Console.WriteLine("{0}", m.Value);
  16. }
  17. }
  18. }
Success #stdin #stdout 0.08s 29636KB
stdin
Standard input is empty
stdout
Selectroasted peanuts
Sugars (sugar, fancymolasses)
Hydrogenatedvegetable oil (cottonseed and rapeseed oil)
Salt