From: Tammo Tjarks Date: 2006-11-04T23:25:16+09:00 Subject: behavior of substitutions with sub Hello, I have seen a somehow strange behavior with Strings and the sub-method. Maybe you cen give me an idea if it is a bug and where it comes from. It have seen the problem when I wanted to make an substition with a sub(//,"") instead of (/ tst = "Das war ja nix" => "Das war ja nix" irb(main):013:0> tst2 =tst => "Das war ja nix" irb(main):014:0> tst2.sub(/nix/,"was") => "Das war ja was" irb(main):015:0> tst2.sub(/(n)+ix/,"$1") => "Das war ja $1" irb(main):016:0> tst2.sub(/(n)+ix/,"#{$1}") => "Das war ja n" irb(main):017:0> tst2.sub(/(n)+(i)+(x)+/,"#{$3}#{$2}#{$1}") => "Das war ja n" irb(main):018:0> tst2.sub(/(n)+(i)+(x)+/,'\3\2\1') => "Das war ja xin" irb(main):019:0> tst2.sub(/(n)+(i)+(x)+/,"#{$3}#{$2}#{$1}") => "Das war ja xin" ================================================================== What I do not understand is, that the substitution in the ''-expression with \1, \2 and \3 work without trouble but when I use the normal ""-String and the #{$1}, #{$2} and #{$3}-notation he seems alway to refer to the last regular expression and not the one in sub-method. It is only an example. In the script I have seen it I cicrcumvent the problem by adding an extra regular expression before without using the result. But I think it is a strange behavior. Any comments about that. Regards, Tammo