From: Logan Capaldo Date: 2007-05-05T00:09:21+09:00 Subject: Re: testing and assigning with regexp's ------=_Part_40955_30780492.1178291360104 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 5/4/07, Christian Neukirchen wrote: > > Tim Hunter writes: > > > Mike Steiner wrote: > >> I'm new to Ruby, and in a little program I'm writing, I have code > >> like this: > >> > >> str = '' > >> if /something/.match(str) > >> str = /something/.match(str)[1] > >> end > >> > >> Is there a more elegant way to do this? > >> > >> Mike Steiner > >> > > str = '' > > m = /something/.match(str) > > str = m[1] if m > > str = str[/something/, 1] || str In that vein, str.gsub!(/\A.*(something).*\z/, '\\1') -- > Christian Neukirchen http://chneukirchen.org > > ------=_Part_40955_30780492.1178291360104--