From: Carlos Date: 2004-10-07T21:44:12+09:00 Subject: Re: Index of multiple similar strings [Milo Thurston , 2004-10-07 14.19 CEST] > I'm trying to read through a file like this: > http://www.genomics.ceh.ac.uk/~milo/example.html > In order to count the number of N tracts and locate their > positions. My code goes like this: > > dust_seq = # file in url above > nums = 0 > d.dust_seq.scan(/[N]+/) do |blah| > nums += 1 > puts "Index #{d.dust_seq.index(blah.to_s)}" > done > puts "Num of Ns: #{nums}" > > In the example, the index for the third of the N groups > is reported as the same as the first, as it's small enough > to fit within it. Is there any way around this? (not tested): nums = 0 idx = 0 while idx = dust_seq.index /N+/, idx nums += 1 puts "Index #{idx}" idx = Regexp.last_match.end(0)+1 end puts "Num of Ns: #{nums}"