From: Bernard Kenik Date: 2007-07-21T05:16:13+09:00 Subject: Re: line.split with some complicating factors... Marc Hoeppner wrote: > >> ranges = str.scan(/(\d+)\.\.(\d+)/).map {|a,b| a.to_i..b.to_i } >> betweens = str.scan(/(\d+),(\d+)/).map {|a,b| (a.to_i+1)..b.to_i-1 } >> >> >> David > > Took me a bit, but got it working - perfect, thanks a lot! an alternate way which might be clearer would a = 50586..50639,50795..51859,60005..60058,60256..61236 b = [] 0.upto(a.size - 2) do |i| c = a[i].last + 1 d = a[i+1].first - 1 b << (c..d) end p a => [50586..50639, 50795..51859, 60005..60058, 60256..61236] p b => [50640..50794, 51860..60004, 60059..60255] -- Posted via http://www.ruby-forum.com/.