From: Daniel Sheppard Date: 2008-04-03T12:32:01+09:00 Subject: Re: confused by 'test'.gsub(/.*/,'x') > I would have expected one greedy match for the entire text. > Instead I guess it's first getting the zero match and then > the full match. Actually, it's vice versa. It matches the whole string (greedy), then matches the end of string. The "test" string is seen by the regex engine as: test .* first matches "test". is a special 'character' that is not consumed by ".", so the remaining string is then "", This is also matched, as it contains zero or more characters (but is not then matched infinitely, as the position in the string has not advanced. Dan.