import re
a = re.findall('\d', 'abc123def56zz')
print(a) # ['1', '2', '3', '5', '6']
b = re.findall('\d+', 'abc123def56zz')
print(b) # ['123', '56']
# match
fn = 'abc123def56zz'
c = re.match(r'([a-z-. ]+)(\d{,5})(.*)',fn).groups()
print(c) # ('abc', '123', 'def56zz')
files= ['abc123def56zz']
file = 'abc123def56zz'
a = sorted(files, key=lambda file : int(re.findall('\d+', file)[0])) # 첫 숫자로 정렬
# 숫자 정렬
print(re.findall('\d+', file))
b = sorted(a, key=lambda file : re.split('\d+', file.lower())[0])
# 숫자 제외하고 나누기
print(re.split('\d+', file.lower())) # ['abc', 'def', 'zz']
댓글