Albert Wagner wrote: > Thank you, Robert. I was unaware of both the csv module and the Ruby > Cookbook. I got this far with String#split but couldn't get rid of the > quote in element 0 and how to force empty strings for the trailing commas: > > irb(main):048:0> x > "\"aaa\",,\"ccc\",,,\"fff\",,," > irb(main):049:0> y = x.split(/\"\s*,\s*\"|\"\s*,|\s*,\s*\"|\s*,|\s*\z/) > ["\"aaa", "", "ccc", "", "", "fff" Hi Albert, The CVS module is probably the easiest, but since I love regexps so much, here's another option. The "scan" method actually does recursion for you. There are a number of ways you can manage this, but the easiest is: irb(main):165:0> string "\"aaa\",xxx,\"ccc\",,\"a,b\",\"fff\",,," irb(main):166:0> string.scan(/".*?"|[^,]+/) ["\"aaa\"", "xxx", "\"ccc\"", "\"a,b\"", "\"fff\""] to just return the data, or irb(main):167:0> string.scan(/".*?"|[^,]*/) ["\"aaa\"", "", "xxx", "", "\"ccc\"", "", "", "\"a,b\"", "", "\"fff\"", "", "", "", ""] to maintain your null data points. --- SER -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==-----