From: Josselin Date: 2007-04-27T22:15:12+09:00 Subject: Re: string replacement... On 2007-04-27 09:37:25 +0200, Bj�rn Paetzel said: > Josselin schrieb: >> I have a string : str = "/proposal/list/31551" >> >> I would like to change the 31551 by another value "9999", but I don't >> see whicj method I should use ? > > How about: > > str.gsub! "31551", "9999" > > or to replace "the number at the end": > > str.gsub! /[0-9]+$/, "9999" > > :) thanks Bj�rn , expected result for digits, but I forgot any other characters , replacing the item after the last / was my goal irb(main):007:0> str = "/proposals/list/31555" => "/proposals/list/31555" irb(main):012:0> str.gsub! /[0-9]+$/, "9999" => "/proposals/list/9999" but irb(main):013:0> str2 = "/proposals/list/abcde" => "/proposals/list/abcde" irb(main):014:0> str2.gsub! /[0-9]+$/, "9999" => nil josss :-))