From: sabbyxtabby@... (Sabby and Tabby) Date: 2003-11-23T23:22:13+09:00 Subject: Re: $& write-protected? "Simon Strandgaard" wrote: > That will work. But I also need to so assignment to $1 - $9, $', $`, $+ class MatchData def MatchData.[](pre, match, post, *captures) str = [pre, match, post] * '' match = Regexp.quote(match.dup) captures.collect! do |cap| c = Regexp.quote(cap) i = match.index(c) or raise ArgumentError, "Not a backreference: #{cap.inspect}" match[i + c.size, 0] = ')' match.slice!(0, i) + '(' end str =~ /#{captures * '' + match}(?=.{#{post.size}}\z)/m $~ end end $~ = MatchData[*%w/alpha beta charlie beta be e ta t a/] p [$`, $&, $', *$~.captures]