I'm looking at the tutorial given here :-
https://docs.python.org/2/howto/regex.html#lookahead-assertions
I want to exclude files that end in .pqr.gz and I'm not quite sure how to do that.
e.g., the expected behaviour is :-
f1.gz => succeed
f1.abc.pqr => succeed
f1.pqr.gz => fail
f1.abc.gz => succeed
The best regex I could come up with was :-
r'.*[.](?=[^.]*[.][^.]*)(?!pqr[.]gz$)[^.]*[.][^.]*$'
This excludes files that end in .pqr.gz but doesn't for example allow files that are just f1.gz (i.e. first case I wrote above).
Any ideas on how this can be improved?
EDIT :- There are better ways to do this (e.g., using string.endswith
), but I'm curious about how to do this with a regex purely as an exercise.