From: Robert Klemme Date: 2010-04-14T14:45:05+09:00 Subject: Re: How to find multiple matches in a string On 13.04.2010 19:01, Alex DeCaria wrote: > Andrea Dallera wrote: >> Hei, >> >> s = 'abcde_abcde_abcde' >> m = s.scan(/b/) >> p m # ['b','b','b'] > Thanks Andrea. But is there a way to also find the locations (indexes) > of the 'b' characters? irb(main):012:0> s="a "*5 => "a a a a a " irb(main):013:0> s.scan(/a+/) { p $~, $~.offset(0) } # [0, 1] # [2, 3] # [4, 5] # [6, 7] # [8, 9] => "a a a a a " irb(main):014:0> Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/