tsunami
log in
email
password
links
newest items
tag list
syntax reference
tag:time
history
item name
tags
==Code {{ static void TestCoolness(string test) { Console.WriteLine(new string('-', test.Length)); Console.WriteLine(test); Console.WriteLine(new string('-', test.Length)); const string Pattern = @"(?xn) \s* # match this so we can easily find invalid text ( (?<v>[^',]+) # either capture an unquoted token | '(?<v>([^']|'')+)' # or the quoted token, without the (unescaped) quotes ) \s* # ditto above \s* ( ,|$ # a token is terminated by a comma (outside a quoted # string) or the end of the string )"; var matches = Regex.Matches(test, Pattern).Cast<Match>(); if (matches.Sum(m => m.Length) == test.Length) Console.WriteLine(matches .Select(m => m.Groups["v"].Value.Replace("''", "'")) .Join("\n")); else Console.Error.WriteLine( "! {0}\n! {1}", test, Enumerable.Range(0, test.Length) .GroupJoin( matches.SelectMany(m => Enumerable.Range(m.Index, m.Length)), n => n, n => n, (n, g) => g.Any() ? " " : "^") .Join("")); } }} ==Input {{ TestCoolness("a,b,c"); TestCoolness("a, 'b','c, still c'' yes, even still c'"); TestCoolness("a,'b,c"); TestCoolness("a,b,c'"); TestCoolness("' ' 'a,b,c'"); }} ==Output {{ ----- a,b,c ----- a b c --------------------------------------- a, 'b','c, still c'' yes, even still c' --------------------------------------- a b c, still c' yes, even still c ------ a,'b,c ------ ! a,'b,c ! ^ ------ a,b,c' ------ ! a,b,c' ! ^^ ------------- ' ' 'a,b,c' ------------- ! ' ' 'a,b,c' ! ^^^^^ }}
some permissive license goes here
contact