From: "Wolfgang Nádasi-Donner" Date: 2007-11-02T14:51:35+09:00 Subject: Re: backslash sequences\1\2 in regexs (backreferences) Morton Goldberg wrote: > On Nov 2, 2007, at 12:59 AM, 7stud -- wrote: > >> --output:-- >> got >> >> That makes it sound like \1 and \2 can be freely used in the >> replacement >> string. There is no mention of the fact that single quotes are >> required >> to keep them from being interpreted as chars written in octal. That >> description is very misleading > > No, it's not, That single quotes are required has nothing to do with > gsub. It's something you should know from your understanding of how > the Ruby interpreter handles double quoted strings. As Mike Stok said > the string literal is converted to "a\002\001" long before gsub is > called. > > Regards, Morton You should simply use "double-quote-double-quote" irb(main):001:0> puts "fred:smith".gsub(/(\w+):(\w+)/, '\\2, \\1') smith, fred Wolfgang Nádasi-Donner -- Posted via http://www.ruby-forum.com/.