数字字母混合排序

来源:互联网 发布:中海达v30网络rtk设置 编辑:程序博客网 时间:2024/04/29 16:48
a = ['1', '10', '100', '2', '42', 'hello', 'x1', 'x20', 'x100', '42x', '42y', '10.1.2', '10.10.2', '10.8.2']a.map {|i| i.gsub(/\d+/) {|s| "%08d" % s.to_i } }.zip(a).sort.map{|x,y| y}
a.sort_by{|i|i.gsub(/\d+/) {|s| "%08d" % s.to_i }}
0 0