Skip to content

Instantly share code, notes, and snippets.

@matiasherranz
Created September 26, 2014 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matiasherranz/3230dce4483b1119aca6 to your computer and use it in GitHub Desktop.
Save matiasherranz/3230dce4483b1119aca6 to your computer and use it in GitHub Desktop.
Get filename extension function, using a regex.
import re
def get_extension(filename):
regex = re.compile(r'^.*?[.](?P<ext>tar\.gz|tar\.bz2|\w+)$')
return regex.match(filename).group('ext')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment