From: Josh Cheek Date: 2010-03-02T10:37:14+09:00 Subject: Re: MatchData captures... expected two items, but got one? --000e0cd110967c60e10480c767a4 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Mar 1, 2010 at 7:15 PM, Sarah Allen wrote: > Looking at the MatchData docs: > http://ruby-doc.org/core/classes/MatchData.html#M001278 > > It looks like I should be able to get an array from .captures with every > match. I swear I've done this before, but I was teaching a class today > and couldn't figure out what's going on in this simple example... maybe > I typed something wrong and just need another pair of eyes. > > > $ irb > >> test = "word1 foo word2" > => "word1 foo word2" > >> m = test.match /(word.)/ > => # > >> m.captures > => ["word1"] > > testing the same string and expression in http://www.rubular.com yields > two matches > > $ ruby -v > ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.7.0] > > Can anyone give me a clue? > > Thanks in advance, > Sarah > -- > Posted via http://www.ruby-forum.com/. > > Not sure what the answer is with match, I usually use scan like this: test = "word1 foo word2" m = test.scan(/word./) m # => ["word1", "word2"] --000e0cd110967c60e10480c767a4--