On Aug 16, 11:56 am, Alex Young <a... / blackkettle.org> wrote:
> If you ignore that the quote character can also appear inside column
> data, then this will work, ishkinda.
>
> 'foo,bar,"foo,bar"'.scan(/("[^"]+")|([^,]+)/).flatten.compact
> => ["foo", "bar", "\"foo,bar\""]

That's very cool, granting that there are still a number of conditions
for which it'll go bust. But I'm a little confused about how a pattern
like [^,]+ gets an element, given that (unless I'm mistaken) in a
standard regexp, it would only match on a string that contained a
series of commas that beginning of a line, like ",,," or "abc\n,,".
What's my mistake/confusion here?

> Besides, when a
> library is as easy to use as either CSV *or* FasterCSV (my preference is
> for the latter, but it's not in stdlib), what's the point in stressing?

The only point is in learning - I like to be able to use packages
without the effort that went into making them, but I don't really like
jumping from DIY to "Here's a way, and don't worry about how it
works...it's magic!"

Thanks for the info,
Andrew