From: David Alan Black Date: 2004-05-31T21:33:44+09:00 Subject: Re: gsub!, replace with \' Hi -- Simon Strandgaard writes: > I think I read somewhere that perl6 uses $ in the regexp replacement string, > in order to avoid our escaping hell. I think this is a good initiative. > So escape can be used freely: > "hello".gsub!(/h/, %q|\'|) #-> \'ello > "hello".gsub!(/(.)$1/, '$&$1') #-> helllo > > Maybe we should do an RCR.. use dollar in regexp? Hmmm... I thought Ruby was moving more in the direction of getting rid of Perl-like global variables :-) But anyway, I think the thing you're describing might lead to some awkward things. I think it's more logical to treat $1 as just a regular variable for purposes of compiling the regular expression: /(def)/.match("abcdef") puts $1 # def /ABC#{$1.upcase}/.match("whatever") If your change were made, $1 would be nil in the last line because there are no captures. And here, you'd get a kind of postponed compilation of re: /(abc)/.match("abc") re = /(blah)#{$1}def/ Sorry for the dumb examples... but I think the problems would be real. David -- David A. Black dblack@wobblini.net