From: Robert Klemme Date: 2008-08-02T17:54:01+09:00 Subject: Re: Gsup with variable when replacing On 28.07.2008 14:51, Sebastian Hungerecker wrote: > Romain LOMBARDO wrote: >> f3 = line.gsub!(/\d+$/,'\1') > > \1 means "first group", but there are no groups in your regex. \0 means "whole > match", so that's the one you want. I wasn't aware that \0 does the job as well. I always use \& for the whole match. Learn something new every day. :-) > Another thing: gsub! is the mutating variant of gsub. It will return nil when > no change occurs or self when there is a change. Either way it does not make > sense to store its return value. > And yet another thing: there is no sense in using gsub (as opposed to sub) > with a regex that only matches once anyway. Absolutely. Another remark, iterating through a file can be made easier: File.foreach("D:/digisoft/1b.txt") do |line| line.gsub!(/\d+$/,'\\&') puts line end Kind regards robert