Last active
August 14, 2017 10:15
-
-
Save cossio/a73e82fd69e3ce49c0ec1da4e6a2372d to your computer and use it in GitHub Desktop.
Sort strings in natural order (numbers are inside are treated by value).
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
# done by Sebastian Pfitzner | |
function naturalsort(x::Vector{String}) | |
f = text -> all(isnumber, text) ? string(Char(parse(Int, text))) : text | |
sorter = key -> join(f(c) for c in matchall(r"[0-9]+|[^0-9]+", key)) | |
sort(x, by=sorter) | |
end | |
# see https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment