From: Fred Phillips Date: 2008-07-28T21:51:07+09:00 Subject: Re: Gsup with variable when replacing --O5XBE6gyVG5Rl6Rj Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon Jul 28 21:44:41 2008, Romain LOMBARDO wrote: > Hi people, >=20 > I'm trying to transform this kind of line : > 123232321 > FOOFOOFOO > .. > 2431232 > BARBARBAR >=20 > to > 123232321 (actually XML) > 2431232 > So I have coded this script > File.open("D:/digisoft/1b.txt","r") do |f2| > while line =3D f2.gets > f3 =3D line.gsub!(/\d+$/,'\1') > puts f3 > end > end >=20 > but Ruby doesn't seem to apraciate .. I search example and I found > that variable as $1, \1, &$ could do this job but i can't get it > works. > How can I get the match of my regexp and add blocks please ? >=20 > thanks you >=20 You=E2=80=99re missing the brackets around the \d+, like so: f3 =3D line.gsub(/(\d+)$/,'\1') Note that I am also using String#gsub not String#gsub! as that will change your line variable also. --=20 Fred O. Phillips BBC7 7572 755F 83E0 3209 504A E4F7 874F 1545 9D41 --O5XBE6gyVG5Rl6Rj Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAkiNwM0ACgkQ5PeHTxVFnUG+6gCgvjOhC71di5HFhd/F+EZrgf37 MzsAoIiEE4F6LKL3FS+x9j6rX1sZUqfv =KC43 -----END PGP SIGNATURE----- --O5XBE6gyVG5Rl6Rj--