

Natural sorting - maxwell
http://www.davekoelle.com/alphanum.html

======
joeyh
[http://search.cpan.org/~sburke/Sort-
Naturally-1.02/lib/Sort/...](http://search.cpan.org/~sburke/Sort-
Naturally-1.02/lib/Sort/Naturally.pm)

Available since 2001.

------
pavlo
There is a nice "oneliner" in Ruby for that, created by Piers Cawley:
<http://j.mp/anfTlJ>

And for python there is a nice Article on CodingHorror: <http://j.mp/aCxlI3>
Hope it's useful :)

------
_delirium
Is there an easy way to get 'ls' to use this ordering?

~~~
inimino

      ls -v

~~~
_delirium
Huh, so it seems! Has that been there forever, or was it added semi-recently
in response to things like this post?

------
inimino
Available in GNU userland as `sort -V`.

------
keefe
Excellent post. It's focused, unbiased, simple, covers a useful problem and
includes source.

------
jamesshamenski
You should sell this to microsoft for millions.

~~~
d0mine
Is it a sarcasm?

It seems that Microsoft's StrCmpLogicalW() has exactly desired behavior.
Besides it is trivial to implement:

    
    
      def natural_key(key):
          """See http://www.codinghorror.com/blog/archives/001018.html
    
          >>> L = 'a01 a9 b1 b10 b9'.split()
          >>> L.sort(key=natural_key)
          >>> ' '.join(L)
          'a01 a9 b1 b9 b10'
          """
          return [int(chunk) if chunk.isdigit() else chunk
                  for chunk in re.split(r'(\d+)', key)]

