From: Sarah Allen Date: 2010-03-03T00:33:57+09:00 Subject: Re: MatchData captures... expected two items, but got one? Robert Klemme wrote: > Where exactly is the difference between the functionality and the > description? > > Kind regards > > robert The docs are correct, but not particularly helpful in their description. It is not ideal to use a word in its definition: captures: "Returns the array of captures" http://ruby-doc.org/core/classes/MatchData.html#M001278 If I had looked closer at the example I might have figured it out, since upon reflection it is pretty standard regex. My attempts at debugging with rubular further confused me since it reports two matches from the single capture expression. botp pointed out that I needed to specify one capture per result. Which the ruby-doc example also illustrates: f1,f2,f3,f4 = /(.)(.)(\d+)(\d)/.match("THX1138.").captures f1 #=> "H" f2 #=> "X" f3 #=> "113" f4 #=> "8" I was confused by the rubular experiment and also by the String.scan docs http://ruby-doc.org/core/classes/String.html#M000812 where captures are described as "groups"... or maybe they were just referring to the result of evaluating the capture with a scan. Thanks everyone for your help! Sarah -- Posted via http://www.ruby-forum.com/.