From: Wybo Dekker Date: 2008-04-03T06:39:04+09:00 Subject: Re: confused by 'test'.gsub(/.*/,'x') Jens Wille wrote: > as soon as you anchor the regexp at the beginning of the string it > gives the expected result: > > irb> 'test'.gsub(/\A.*/) { |m| p m; 'x'} > "test" > =>"x" > > or just do: > > irb> 'test'.sub(/.*/) { |m| p m; 'x'} > "test" > =>"x" sure, that works, and so does test.gsub(/.+/,'x'). The point is that I don't understand why test.gsub(/.*/,'x') gives me 'xx', since .* means: zero or more of any character, except the newline character, i.e.: all of the string should be replaced with a single x, as far as I can see. -- Wybo