From: David Alan Black Date: 2001-11-03T08:19:17+09:00 Subject: [ruby-talk:24229] Re: literal \0 in String#gsub replacement Hello -- On Sat, 3 Nov 2001, Ryan Leavengood wrote: > > 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. I seem to be on a "heisenbug" spree: first getting bitten by shell quoting, now this :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav