From: Pierre-Charles David Date: 2001-12-20T01:39:55+09:00 Subject: [ruby-talk:28957] Re: Backslash Sequence Bug? Jesse Jones writes: > According to the pickaxe book (page 64), this: > > text = "fred:smith" > puts text.sub(/(\w+):(\w+)/, "\2, \1") > > should print "smith:fred", but on my system it prints ", ". Look closer. The pickaxe book example uses single quotes: '\2, \1'. When you use double quotes, Ruby interprets the blackslash sequences as character codes. Single quotes prevent interpolation of the backslashes by Ruby, so they can be seen and interpreted correctly by String#sub. % ruby -e 'p "\2, \1".size' 4 % ruby -e "p '\2, \1'.size" 6 You can still use double quotes, but then you need to double the backslashes: "\\2, \\1". -- Pierre-Charles David (pcdavid emn fr) Computer Science PhD Student, �cole des Mines de Nantes, France Homepage: http://purl.org/net/home/pcdavid