From: Robert Klemme Date: 2007-06-03T16:30:33+09:00 Subject: Re: No way of looking for a regrexp match starting from a particular point in a string? On 03.06.2007 07:30, Nobuyoshi Nakada wrote: > Hi, > > At Sun, 3 Jun 2007 13:56:05 +0900, > Patrick Hurley wrote in [ruby-talk:254059]: >> I think he wanted MatchData objects. The String#index method returns >> the index (numeric position of the match). But if all you want are >> captures, then index is a good solution. > > String#index also sets $~. But then you can also use String#scan: irb(main):002:0> "ababb".scan(/(a)b+/) {p $~} # # => "ababb" irb(main):003:0> "ababb".scan(/(a)b+/) {p $~.to_a} ["ab", "a"] ["abb", "a"] => "ababb" Ken, why do you need MatchData objects? Kind regards robert