Skip to content

Instantly share code, notes, and snippets.

@matiasherranz
Created September 26, 2014 15:54
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/284b48cf3c00650d1159 to your computer and use it in GitHub Desktop.
Save matiasherranz/284b48cf3c00650d1159 to your computer and use it in GitHub Desktop.
Get filename extension function, using a regex. Keep the point.
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