Created
October 27, 2011 23:59
-
-
Save rubypanther/1321247 to your computer and use it in GitHub Desktop.
Sort an array of strings by their first word and then their first number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%w/ foo11 foo2 3foo foo4 bar2 foo1 bar99-a /.sort do |a,b| | |
[a[/[[:alpha:]]+/],a[/[[:digit:]]+/]] <=> | |
[b[/[[:alpha:]]+/],b[/[[:digit:]]+/]] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment