From: GOTO Kentaro Date: 2002-05-09T02:48:53+09:00 Subject: Re: RegExp: using $& in 2nd gsub argument At Thu, 9 May 2002 02:23:57 +0900, Morris, Chris wrote: > i want to do the following: > > "test\n (he\nllo) \nhey".gsub(/\((.*\n.*)\)/, $&.gsub("\n", '')) Move the second argument to inside of block, i.e., "test\n (he\nllo) \nhey".gsub(/\((.*\n.*)\)/m){ $&.gsub("\n", '') } A method is evaluated after all arguments are evaluated. So, any pattern matching isn't done when $& is evaluated. On the other hand, block is evaluated every pattern matching. See also: http://www.rubycentral.com/book/ref_c_string.html#String.gsub Hope this helps, -- Gotoken