From: 7rans Date: 2009-08-28T21:10:57+09:00 Subject: Re: I need a string#all_indices method--is there such a thing? On Aug 28, 4:25 am, timr wrote: > In ruby you can use string#index as follows: > str = "some text" > str.index(/t/) > =>5 > > But what if I want to get all the indices for a regex in the string? > Is there an string#all_indices method? Facets has: def index_all(s, reuse=false) s = Regexp.new(Regexp.escape(s)) unless Regexp===s ia = []; i = 0 while (i = index(s,i)) ia << i i += (reuse ? 1 : $~[0].size) end ia end