From: Brian Candler Date: 2003-04-25T19:50:17+09:00 Subject: Re: Array String.match(Regexp) On Fri, Apr 25, 2003 at 07:12:47PM +0900, Vlada Soucek wrote: > I'd like to know, what is the easiest way of doing the perlish > > ($i,$j,$k) = $_ =~ /delim(\S+):(\S+):(\S+)/ > > =~ operator in ruby returns nil/number > I have found just one solution, which uses global $variables. > > $_.sub( /regexp_(with)_multiple(.*)/ , "" ) ; > i = $1 ; > j = $2 ; > k = $3 ; > > But I don't like global variables. Ruby functions can return > everything.. > a = $stdin.readlines() > So isn't there somewhere > String.match( Regexp ) that returns Array of matches ? foo = "junkdelimabc:def:ghi" m = /delim(\S+):(\S+):(\S+)/.match(foo) # m is a MatchData object p m.to_a # >> ["delimabc:def:ghi", "abc", "def", "ghi"] i.e. m[1] is like $1, m[2] is like $2 etc. Regards, Brian.