From: "J.Hawkesworth" Date: 2003-02-22T02:28:26+09:00 Subject: Re: Regexp help: Parsing a CSV file No doubt other people will suggest much more elegant solutions but I'd save the file as tab separated (perhaps this isn't an option with your version of Excel? or perhaps tabs cause different problems?). Presumably I could then just use line.split("\t") Hope this helps, Jon -----Original Message----- From: Tim Bates [mailto:tim@bates.id.au] Sent: 21 February 2003 12:14 To: ruby-talk ML Subject: Regexp help: Parsing a CSV file I've dumped a CSV (comma separated values) file from Excel, and I want to parse it into cels within my Ruby script. Easy enough, you say: line.split(',') But it's a little more complicated than that - see, if the cel has a comma in it, it gets surrounded in quotes. If a cel has a quote in it, it's surrounded by quotes and doubled, eg: Test Te,st Te"st becomes Test,"Te,st","Te""st" Now to use String#split, I would have to write a regexp that will match a comma, provided that comma is preceeded by an even number of quotes. BUT, I don't want the regexp to match the quotes themselves, just the comma. I can't figure this one out... Tim Bates -- tim@bates.id.au ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ _____________________________________________________________________ This message has been checked for all known viruses by Star Internet delivered through the MessageLabs Virus Control Centre. For further information visit http://www.star.net.uk/stats.asp _____________________________________________________________________ Any views or personal opinions expressed within this email may not be those of Talis Information Ltd. The content of this email message and any files that may be attached are confidential, and for the usage of the intended recipient only. If you are not the intended recipient, then please return this message to the sender and delete it. Any use of this e-mail by an unauthorised recipient is prohibited.