From 28f9187f6f08a5b09293d44f1928a7da85c2a7b7 Mon Sep 17 00:00:00 2001 From: nfnty Date: Fri, 2 Oct 2015 15:18:13 +0200 Subject: Fix regex splitting for natural sort, Fixes #381 --- ranger/container/fsobject.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py index a8c70e03..b63781de 100644 --- a/ranger/container/fsobject.py +++ b/ranger/container/fsobject.py @@ -30,7 +30,7 @@ else: from string import maketrans _unsafe_chars = '\n' + ''.join(map(chr, range(32))) + ''.join(map(chr, range(128, 256))) _safe_string_table = maketrans(_unsafe_chars, '?' * len(_unsafe_chars)) -_extract_number_re = re.compile(r'([^0-9]?)(\d*)') +_extract_number_re = re.compile(r'(\d+)') def safe_path(path): return path.translate(_safe_string_table) @@ -144,13 +144,13 @@ class FileSystemObject(FileManagerAware, SettingsAware): @lazy_property def basename_natural(self): - return [c if i % 3 == 1 else (int(c) if c else 0) for i, c in \ - enumerate(_extract_number_re.split(self.relative_path))] + return [int(s) if s.isdigit() else s \ + for s in _extract_number_re.split(self.relative_path)] @lazy_property def basename_natural_lower(self): - return [c if i % 3 == 1 else (int(c) if c else 0) for i, c in \ - enumerate(_extract_number_re.split(self.relative_path_lower))] + return [int(s) if s.isdigit() else s \ + for s in _extract_number_re.split(self.relative_path_lower)] @lazy_property def safe_basename(self): -- cgit 1.4.1-2-gfad0