Robert Klemme wrote:
> Depending on your data that might or might not be sufficient.
Regexps can
> be arbitrarily sophisticated.  Here's another one:
>
> data = []
> line.scan( %r{
>   "((?:[^\\"]|\\")*)" |
>   '((?:[^\\']|\\')*)' |
>   ([^,]+)
> }x ){|m| data << m.find {|x|x}}


I borrowed your regexp.

% class String
%   def parse_csv
%     a = self.scan(
%       %r{ "( (?: [^\\"] | \\")* )" |
%           '( (?: [^\\'] | \\')* )' |
%            ( [^,]+ )
%       }x ).flatten
%     a.delete(nil)
%     a
%   end
% end
%
% ARGF.each_line { | line |
%   p line.chomp.parse_csv
% }

With this input

a,b,"foo, bar",c
"foo isn't \"bar\"",a,b
a,'"just,my,luck"',b

the output is

["a", "b", "foo, bar", "c"]
["foo isn't \\\"bar\\\"", "a", "b"]
["a", "\"just,my,luck\"", "b"]