From: Wilson Bilkovich Date: 2006-05-17T04:44:34+09:00 Subject: Re: Problem with my gsub! On 5/16/06, Guest wrote: > Wilson Bilkovich wrote: > > On 5/16/06, Guest wrote: > >> same gsub! line? > >> > >> Thanks again. > >> > > > > The block form of gsub is one way to go about it: > > counter = 0 > > content.gsub!(/^%%Page:.*([0-9]{1,5})$/) do |match| > > counter += 1 > > "%%Page: #{counter}" > > end > > > > Whatever the block returns is used to replace the matched text. > > Cool. Thank you both very much. This is a very generous forum, I must > say. I wrote that reply prior to coffee, and you'll note that the |match| block variable is unnecessary, since you're not doing anything with it. Also, I meant to say "the value of the block", not "what the block returns". Other than that, it stands up to 6 hours of wakefulness. Heh.