From: raja@... (Raja S.) Date: 2001-11-30T14:56:21+09:00 Subject: [ruby-talk:27030] Re: Help: factored sorting Bil Kleb writes: >I have an array of strings, >a = ["d3", "d33", "d4", "r16", "r33", "d34", "r34"] >which I'd like to sort by both the numerical suffix and by >the alphabetic prefix, i.e., I'd like the result, > ["d3", "d4", "d33", "d34", "r16", "r33", "r34"] This is a case of multi-key sorting: a.sort{ |x,y| keys(x) <=> keys(y) } Now all that is needed is to split your original strings into the component keys used for comparison. Something like: def keys( str ) ary = str.scan(/[a-z]+|\d+/) ary[1] = ary[1].to_i ary end Will probably suffice. Regards, Raja