From: Simon Strandgaard Date: 2004-03-26T02:14:39+09:00 Subject: Re: GString and XSS (Re: groovy) On Thu, 25 Mar 2004 12:29:50 +0900, Tanaka Akira wrote: > In article <87hdweuzit.fsf@serein.a02.aist.go.jp>, > Tanaka Akira writes: > >>> str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m| >>> m[3] + m[2] + m[1] >>> end >> >> I think a regexp with named capture should binds local variables. >> It makes possible to describe your example as follows. >> >> str.gsub!(/(?\s\w)(?\w+)(?\w\s)/) { a + b + c } > > Oops. It should be: > > str.gsub!(/(?\s\w)(?\w+)(?\w\s)/) { c + b + a } Never thought of using named-captures 2 local-variables.. This would be a nice 2 have feature. I have looked a little at perl6 regexp.. above example would then look sligthly different (rubified perl): rules(:a=>'\s\w', :b=>'\w+', :c=>'\w\s') str.gsub!(/ /) { c + b + a } Readability is improved a little ;-) -- Simon Strandgaard