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.
···
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 ?
all, i, j, k = */delim(\S+):(\S+):(\S+)/.match($_).to_a
robert
“Vlada Soucek” suk@artax.karlin.mff.cuni.cz schrieb im Newsbeitrag
news:20030425101238.GA16956@artax.karlin.mff.cuni.cz…
···
Hi
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 ?