Sebastian Hungerecker wrote: > Drew Olson wrote: >> I have a question after studying my own solution for the ruby-wise :) >> Why does this scan return an array of arrays rather than a simple array >> of matches? > > If you don't use groups within your regexp, scan will just return an > array > with the matched strings. If you do however, it will return an array of > arrays, each array containing one string per matched group. > Example: >>> "la=lu,lipp=lapp,slipp=slapp".scan(/\w+=\w+/) > => ["la=lu", "lipp=lapp", "slipp=slapp"] >>> "la=lu,lipp=lapp,slipp=slapp".scan(/(\w+)=(\w+)/) > => [["la", "lu"], ["lipp", "lapp"], ["slipp", "slapp"]] > > > HTH, > Sebastian Hungerecker Thanks, that makes perfect sense. Incidentally, I did only want the results of the grouping returned, however now I understand the rational behind the array of arrays. Very helpful as always. -Drew -- Posted via http://www.ruby-forum.com/.