Created
June 2, 2010 09:37
-
-
Save bradwright/422153 to your computer and use it in GitHub Desktop.
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
import re | |
pattern = re.compile('^.*?((?<!\.[a-z0-9]{8})png|jpg|gif|swf|ico|flv|zip)$') | |
# I want the first two to match, but not the second two | |
file_list = [ | |
'main.ie6.zip', | |
'main.zip', | |
'main.cb1c4aa1.zip', | |
'main.cb1c4aa1.cb1c4aa1.zip' | |
] | |
for f in file_list: | |
print f | |
if pattern.match(f): | |
print pattern.match(f).groups() |
Yeah that's what Norm came up with too:
pattern = re.compile('^.*?(?<!\.[a-z0-9]{8})\.(png|jpg|gif|swf|ico|flv|zip)$')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The lack of a dot before the extension and the fact that the lookbehind is in one of the multiple options in the final matching set is, I think, what causes the failure. This works for me: