From: Albert Wagner Date: 2001-10-14T12:47:43+09:00 Subject: [ruby-talk:22506] Re: extracting from delimited text files Thanks, Sean. I wrestled with scan for awhile but couldn't figure out how to do it. I'll have to brood on your code for awhile. I understand what recursion is, but not in this context. Could you explain about scan doing recursion? > 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! ==-----