On 5/16/06, Guest <pbailey / bna.com> wrote: > Christoffer Sawicki wrote: > >> I've tried \1, but, that gives me even worse results. > > > > '%%Page: \1' or "%%Page: \\1" does what you want. > > Thank you, Christopher! > > Now, could you tell me how to have a counter for that \1? In other > words, I want the numbers to increment, starting from 1 through however > many "%%Page" indicators there are. Is there any way to do that in the > 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.