From: Robert Dober Date: 2007-04-28T06:47:48+09:00 Subject: Re: string replacement... On 4/27/07, Josselin wrote: > > thanks Bj�rn , expected result for digits, but I forgot any other > characters , replacing the item after the last / was my goal Ah that gives the problem a different flavor: (str.split("/")[0..-2] + ["9999"]).join("/") but regexens are probably better after all str.sub!(%r{[^/]*$}, "9999") HTH Robert > > 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 :-)) > > > -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw