```Albert Wagner wrote:

> 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?

Actually, I lied.  It isn't recursing; it is repeating the pattern match.
"scan" just says "find all occurances of this match".  Then it returns an
array of the matches.  In that array are either the match (if you didn't
specify any groups) or sub-arrays of the groups.

For example:

"ababa".scan /a/   # -> ["a", "a", "a"]
"ababa".scan /(a)/ # -> [["a"], ["a"], ["a"]]
"abcdab".scan /ab/  # -> ["ab", "ab"]
"abcdab".scan /(a)(b)/  # -> [["a","b"], ["a", "b"]]

Regular expressions can be complicated, but they are extremely useful.
O'Reilly publishes a "Regular Expressions in a Nutshell" (or is it "Regular
Expressions Explained"?  I don't remember, but O'Reilly publishes it) which
is an excellent reference.

Actually, my CSV regular expression could be shortened to:

string.scan /[^,]*/

[] means to match any character between the brackets.  [^] means to match
any character EXCEPT the characters following the ^.  The star means to
match zero or more characters.  Therefore, [^,]* means to match zero or
more non-comma characters.  Ergo, scan looks at:

"aaa",xxx,"ccc",,"a,b","fff",,,

It first finds "aaa" and stops when it sees a comma.  It sticks that into
an array.  Then it looks further until it finds something that isn't a
comma, which is xxx.  After that, it finds "ccc".  Then it finds two commas
with nothing between; remember, * means to match ZERO or more characters,
so it sticks an empty string in the array.  It keeps doing this until it
reaches the end of the string.  What you get back is an array with:

["\"aaa\"", "", "xxx", "", "\"ccc\"", "", "", "\"a,b\"", "", "\"fff\"",
"", "", "", ""]

--- SER

-----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!