From: David Alan Black Date: 2001-07-16T12:44:12+09:00 Subject: [ruby-talk:17900] Re: regular expressions and string#sub! Hello -- On Mon, 16 Jul 2001, Ernest Ellingson wrote: > This particular code yields some strange results. > I'm using ruby 1.63 on Win2k > > x="aren't" > z="\\\'" > puts x => aren't (expected) > puts z => \' (expected) > x.sub!(/\'/,z) => arentt > puts x => arentt (huh?) Interesting. I can't quite puzzle it out, but it seems to have something to do with the variables $`, $&, and $'. x="before during after" p x.sub(/during/,"\\\`") p x.sub(/during/,"\\\&") p x.sub(/during/,"\\\'") => "before before after" "before during after" "before after after" (ruby 1.6.4 (2001-06-04) [i586-linux] and ruby 1.7.1 (2001-07-03) [i586-linux]) Since I can't puzzle it out, I can't say whether it's a bug :-) But if it's not a bug, I'm not sure what it thinks it's doing. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav