From: Brian Candler Date: 2011-02-27T18:20:15+09:00 Subject: Re: regex gsub Lorenzo Brito Morales wrote in post #984075: > i have already working these phone.gsub(regex, "< > #{regex.match(phone)} >" ) but i think is another way to do it not? > like phone.gsub(regex,"< \1 >") > but the last instrucction does not bring the regex.match It's to do with how double-quoted strings interpret backslashes. irb(main):001:0> "< \1 >" => "< \001 >" irb(main):002:0> '< \1 >' => "< \\1 >" irb(main):003:0> "< \\1 >" => "< \\1 >" irb(main):004:0> "< \\1 >".size => 6 irb(main):005:0> puts "< \\1 >" < \1 > => nil Note that "< \\1 >" contains a *single* backslash - a backslash escaped with a backslash :-) But you'd probably be better using the block form of gsub anyway: phone.gsub(regex) { "< #{$&} >" } -- Posted via http://www.ruby-forum.com/.