From: Robert Klemme Date: 2009-05-19T02:01:30+09:00 Subject: Re: Sorting numbers as strings On 18.05.2009 17:37, Rob Biedenharn wrote: > If you do need to consider things like "FastEthernet..." v. > "GigabitEthernet...", then perhaps you want something like this which > breaks the original string into digits and non-digits and converts the > digits to be integers. > > puts DATA.sort_by {|s| s.scan(/\d+|\D+/).map {|x| x =~ /\d+/ ? > x.to_i : x } } Good point! Here's an interesting variant: puts DATA.sort_by {|s| s.scan(/(\d+)|\D+/).map { $1 ? $1.to_i : $& } } Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/