From: nobu.nokada@... Date: 2003-01-29T07:14:57+09:00 Subject: Re: Perl \G in Ruby regex? Hi, At Wed, 29 Jan 2003 05:39:43 +0900, Chris Wong wrote: > In Perl, \G matches the end position of the last match. > > In Ruby, it matches the start position of the last match. > > \G in Perl is very usual when you need to break down a complex regex > and iterate through it with different regex. > > Is there anyway I can have the Perl \G behavior in Ruby? \G works in String#gsub(!), #scan and #index. p "-abc-def--ghi-".gsub(/\G-\w+/){$&.upcase} #=> "-ABC-DEF--ghi-" p "-abc-def--ghi-".scan(/\G-\w+/) #=> ["-abc", "-def"] p "-abc-def-ghi-".index(/\G\w+/) #=> nil p "-abc-def-ghi-".index(/\G\w+/, 1) #=> 1 p "-abc-def-ghi-".index(/\G\w+/, 5) #=> 5 -- Nobu Nakada