From: Dave Burt Date: 2004-05-14T22:18:56+09:00 Subject: Re: Regexp Error? Perl and Javascript (MSIE) do it too, so I don't propose changing it, but it seems a strange (wrong) behaviour. I would have thought that the second match you refer to should have been included in the first; that is, that the greedy match should match (and then replace) the whole string, including the 0 characters between the last character and the end of the string. But apparently it's not like that. "ts" wrote in message news:200405141224.i4ECOZo25483@moulon.inra.fr... > >>>>> "R" == Robert Klemme writes: > > R> irb(main):025:0> "123-456".gsub(/.*$/, 'X') > R> => "XX" > > R> Applying your explanation, one would have to say that "$" is matched > R> twice. IMHO this is not correct. Or is there another explanation why > R> this gsub happens to return "XX"? > > This is the same explanation. Your regexp means match a string which is at > the end (where end can be \n or the end of string, in this case) > > * first match : "123-456" > * now it's at end > * it can match the empty string > > > $ is like ^ : it don't match a character but a position in the string > (sort of ...) > > > Guy Decoux > > > > >