From: Dave Thomas Date: 2003-05-24T09:49:34+09:00 Subject: Re: why is "does" missing from this sub!-stitution? dblack@superlink.net wrote: > My first thought by way of explaining the $2 behavior was: there's > been no assignment to $2, because the regex has been compiled but the > match hasn't happened yet. But then \2 wouldn't be meaningful.... So > I do actually start to wonder why the previous $2 (nil or otherwise) > persists so long. \2 is substituted by .sub (ie, it gets passed in as part of the string, and .sub looks for and substitutes for it). #$2 is substituted during the initial parse of the string (before .sub is even called) irb(main):008:0> "abcdef".sub(/(..)/, "#$1") => "cdef" irb(main):009:0> "abcdef".sub(/(..)/, "#$1") => "abcdef" Cheers Dave