From: Ryan Leavengood Date: 2001-11-03T08:17:05+09:00 Subject: [ruby-talk:24227] Re: literal \0 in String#gsub replacement > Here's one way: > > irb 23> "apple [cherry] lemon".gsub(/\[(.*?)\]/, "\003\\1") > ==>"apple \003cherry lemon" Actually I tried that too in IRB but when I tried it in actual Ruby I was surprised. That results in the string containing the actual ASCII character with code 003 (which printed as a heart on my Cygwin console.) Since IRB actually calls "inspect" when it prints out, you got what you saw. To actually get a literal \003 in the resulting String, I found that this worked: "apple [cherry] lemon".gsub(/\[(.+?)\]/,'\\\003\1') So Mark, if you want the ASCII character with code 003, use DAB's method, but if you want the literal \003, then use the above. Ryan Leavengood