From: "Peña, Botp" Date: 2008-04-15T12:09:52+09:00 Subject: Re: surprise in sub From: matt neuburg [mailto:matt@tidbits.com] # I didn't say that s was altered. I said that the string you # provide as the second param of sub might not be the string # that gets substituted in - as the example demonstrates. If # you don't find this counterintuitive, you don't; great. But # some people might. Those are the people I'm trying # to help here. m. i think the confusion stems fr the fact that sub/gsub has to reprocess/unescape the string twice 1 for the string as usual for possible escaping chars like \ and " and 2 for the group references like \1 note that this behaviour is present in other languages too. it's been a long time i have *not used the string(as 2nd param) form. I have been getting used to w the block form since not only does it handles the double escaping issue/confusion but it also caters the match vars $1, $`, $& among others.. so, this one eg irb(main):019:0> "hello".gsub(/([aeiou])/, "<\\1>") => "hll" now becomes this irb(main):020:0> "hello".gsub(/([aeiou])/) {|s| "<#{s}>"} => "hll" or this irb(main):026:0> "hello".gsub(/([aeiou])/) {"<#$1>"} => "hll" your choice though. kind regards -botp