From: Josselin Date: 2007-04-27T22:20:13+09:00 Subject: Re: string replacement... On 2007-04-27 10:01:07 +0200, Alex Young said: > William James wrote: >> On Apr 27, 2:29 am, Josselin wrote: >>> 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 ? >>> >>> str.each and block ? or str.rindex('/') and concatenating the new value ? >>> >>> tfyh >>> >>> joss >> >> str[/\d+/] = "9999" > Whoa. I hadn't seen that syntax before. Nice. irb(main):007:0> str = "/proposals/list/31555" => "/proposals/list/31555" irb(main):008:0> str.sub /\d+$/, '9999' => "/proposals/list/9999" irb(main):009:0> str[/\d+/] = "9999" => "9999" don't give the expected result... Stefano's way did it .... ;-)) thanks Alex