From: Kirk Lowery Date: 2002-03-21T01:55:18+09:00 Subject: Regex backreference in method "sub" Consider this code: line = "Some random string data" puts line line.sub!(/(str)ing/,"#{$1}") puts $1 puts line And I get this result: Some random string data str Some random data Instead of what I wanted: Some random string data str Some random str data Apparently, $1 never gets set to the matched group until *after* exiting the sub method. Why not? How do I do this kind of substution? Thanks! Kirk