From: Jamis Buck Date: 2004-12-13T00:20:11+09:00 Subject: Re: Find every location of "th" in string. On 00:10 Mon 13 Dec , Glenn Parker wrote: > Robert Klemme wrote: > >>>"the thin man thinks".scan( /th/ ) { puts $`.length } > >0 > >4 > >13 > >=> "the thin man thinks" > > scan doesn't really do that well. > > "banana".scan(/ana/) { puts $`.length } > 1 > => "banana" > > The second overlapping occurence of "ana" is missed. Well, if you don't mind using a little regexp magic: >"banana".scan(/a(?=na)/) { puts $`.length } 1 3 => "banana" - Jamis -- Jamis Buck jgb3@email.byu.edu http://www.jamisbuck.org/jamis