From: "Ara.T.Howard" Date: 2004-04-07T01:04:18+09:00 Subject: Re: Bug in sub? On Tue, 6 Apr 2004, Martin Hart wrote: > On Tuesday 06 Apr 2004 3:01 pm, Robert Feldt wrote: > > > > Yeah, that's right the "last matched group"; I don't use that one much > > apparently... > > > > Sorry, call me thick but I don't understand that :-) > > Did Guy confirm that it was a bug, or show that it is not a bug? __not_a_bug__ # that's python for not a bug svg% ruby -e 'p "abcdef".sub(/(.)./, "\\+")' "acdef" svg% /(.)./ and '\+' - match a char, followed by another char. remember the first char - replace the entire match with the remembered first char abcdef -> acdef -- - - svg% ruby -e 'p "abcdef".sub(/(.).(..)/, "\\+")' "cdef" svg% /(.).(..)/ and '\+' - match a char, followed by another char. followed by two more chars. remember the last two chars (and the first) - replace the entire match with the remembered last two chars (which is the 'last matched group') abcdef -> cdef ---- -- -- -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done ===============================================================================