From: Simon Strandgaard Date: 2004-03-24T22:29:27+09:00 Subject: Re: GString and XSS (Re: groovy) On Wed, 24 Mar 2004 20:50:17 +0900, Tanaka Akira wrote: [snip] > Another example is confusing String#gsub's 2nd argument. gsub can > interpret "...#{1}..." as '...\1...'. This avoids confusing escape > mechanism. > > I'd like to see it in Ruby. RCR? With oniguruma (Rubys new regexp engine) you can use named backreferences. But that is not what you ask for. Another possibility would be to pass a block to gsub str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m| $3 + $2 + $1 end And then use $1..$9, but it seems more complex. BTW: Why is 'm' of class String. It would be nice if it were an instance of MatchData. If it had been a MatchData object, then the following piece would have worked. str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m| m[3] + m[2] + m[1] end -- Simon Strandgaard