From: "Morris, Chris" Date: 2002-05-09T02:23:57+09:00 Subject: RegExp: using $& in 2nd gsub argument i want to do the following: "test\n (he\nllo) \nhey".gsub(/\((.*\n.*)\)/, $&.gsub("\n", '')) but it fails because $& is nil. If $& was filled in time for the 2nd gsub, it'd work: irb(main):006:0> "test\n (he\nllo) \nhey" =~ /\((.*\n.*)\)/ 6 irb(main):007:0> $& "(he\nllo)" irb(main):008:0> "test\n (he\nllo) \nhey".gsub(/\((.*\n.*)\)/, $&.gsub("\n", '')) "test\n (hello) \nhey" Bigger picture -- I've got source code like this: procedure Name; begin assert('this thing', (x = 5)); end; ... and I want to make all the assert calls on the same line: procedure Name; begin assert('this thing', (x = 5)); end; This regexp: /assert.*;/m correctly matches, and then I can strip the newlines out of $&, but it'd be nice if there was a way to do this in a single .gsub call. Is there? Chris Morris chris.morris@snelling.com