: hello to all!
:
: I'm new to python , worked with regexp in javascript only, and I'm
: stuck with one little problem, I want to know if File has extension:
: .zip .7z .gz .tar ...(only Compressed Files).
:
: But if it's .rar, it must not be xxx.partN.rar ('N' is a number and
: 'xxx' can be anything) UNLESS 'N' is '1' or '01' '001' etc.
:
: Any help will be greatly appreciated.
:
import re
rar = re.compile(".+\.part[^(0*1)]\.rar") #invalid rar's
ext_list = ['zip','7z', 'gz', 'tar', 'rar'] #and whatever else
def foo(n):
if n[n.rfind('.') + 1:] in ext_list:
if not n[-3:] == 'rar':
return True #valid not rar file
elif rar.match(n):
return False #invalid rar file
return True #valid rar file
return False #not in ext_list
[\code]