From: kwatch@... (kwatch) Date: 2002-06-20T11:27:27+09:00 Subject: Re: Q: n-times matching Thank you very much. I adopt your first example. regards, kwatch nobu.nokada@softhome.net wrote in message news:<200206180254.g5I2sl227739@sharui.nakada.kanuma.tochigi.jp>... > Hi, > > At Tue, 18 Jun 2002 04:37:11 +0900, > kwatch wrote: > > You showed three ways to make my desire. > > Which is the fastest? Please tell me if you know it. > > I ordered in faster first. > > String#index needs to adjust multibyte alignment each time, and > it's slow in 1.6. And the last example need to create new > Regexps each time. > > And errata. > > pos = 0 > > while pos = str.index(/<(\/?\w+)>/, pos) do > while str.index(/<(\/?\w+)>/, pos) do > > print $1, "\n" > > pos += $1.size > pos = $~.end(0) > > end > > > pos = 0 > > while str =~ /\A.{#{pos}}.*?<(\/?\w+)>/ do > while str =~ /\A.{#{pos}}.*?<(\/?\w+)>/m do > > print $1, "\n" > > pos = $&.size > pos = $~.end(0) > > end