From: Robert Klemme Date: 2010-12-07T23:15:39+09:00 Subject: Re: Split version requirements On Tue, Dec 7, 2010 at 6:47 AM, Ammar Ali wrote: > On Tue, Dec 7, 2010 at 7:20 AM, Intransition wrote: >> Of course, just my luck it doesn't work in Ruby 1.8 :-( > > I should have mentioned that. > > Just a thought, I suspect you might have already considered, why not > just use match instead of split? > >>> /(\w+)\s+([>=<]\s*\d+\.\d+)\s+([>=<]\s*\d+\.\d+)/.match("rake > 0.8 < 1.0").captures > [ "rake", "> 0.8", "< 1.0" ] > > Sure it's long and not as elegant as split, but it's clear, I think, > explicit, and cross-version compatible. +1 And if it is too long to read easily we can always use /x: %r{ \A # leading word: (\w+) \s+ # 1st version no: ([>=<] \s* \d+(?:\.\d+)+) \s+ # 2nd version no: ([>=<] \s* \d+(?:\.\d+)+) }x.match ... Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/