From: Robert Klemme Date: 2004-05-14T21:18:56+09:00 Subject: Re: Regexp Error? "ts" schrieb im Newsbeitrag news:200405141118.i4EBIo422693@moulon.inra.fr... > >>>>> "R" == Robert Klemme writes: > > R> irb(main):023:0> "123-456".gsub(/.*/, 'X') > R> => "XX" > > * first match : "123-456" > * now it's at end > * second match with the empty string > > R> irb(main):024:0> "123-456".gsub(/^.*/, 'X') > R> => "X" > > * first match : "123-456" > * now it's at end > * it can't match the empty string because there is ^ in the regexp That explains it. I still have to say that I find this a bit surprising. Moreover, case strikes me as error: irb(main):025:0> "123-456".gsub(/.*$/, 'X') => "XX" Applying your explanation, one would have to say that "$" is matched twice. IMHO this is not correct. Or is there another explanation why this gsub happens to return "XX"? Regards robert