From: Elias Karakoulakis Date: 2002-12-31T19:32:20+09:00 Subject: Re: How to translate this Perl regex Helmut Leitner wrote: >Someone said that Ruby can do anything that Perl does. >How would you write this Perl regex > > $s =~ s/(pat1+)pat2(pat3*)/&foo($1,$2)/ge; > >in Ruby? > > str.gsub /(pat1+)pat2(pat3*)/ { |m| foo(m[1], m[2]) } Note that it;s better to use m[1] and m[2] instead of $1/$2 .. Happy new year!