From: Bertram Scharpf Date: 2009-08-31T23:27:52+09:00 Subject: Re: text lines manipulation Hi, Am Montag, 31. Aug 2009, 20:33:19 +0900 schrieb George George: > m=Regexp.new(re,Regexp::IGNORECASE); > if m.match(line) > int1 = m.match(line)[1]; > c1 = m.match(line)[2]; > int2 = m.match(line)[3]; > puts int1<< c1 << int2 > end After `m.match(line)' the match is stored in the $~ global variable. You don't need to execute it three more times. $~[1] is equivalent to $1. The `<<' operator modifieds the string `int1'. Better is here the operator `+'. It's sure a matter of taste but in general shorter code is easier to read. if line =~ /(\d+)(-)(\d+)/i then int1 = $1 c1 = $2 int2 = $3 puts int1 + c1 + int2 end This is for the not faint-hearted: int1, c1, int2 = *$~.captures Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de