How can I get file extensions with JavaScript?

Newer Edit: Lots of things have changed since this question was initially posted – there’s a lot of really good information in wallacer’s revised answer as well as VisioN’s excellent breakdown Edit: Just because this is the accepted answer; wallacer’s answer is indeed much better: return filename.split(‘.’).pop(); My old answer: return /[^.]+$/.exec(filename); Should do it. … Read more

Extracting extension from filename in Python

Yes. Use os.path.splitext(see Python 2.X documentation or Python 3.X documentation): >>> import os >>> filename, file_extension = os.path.splitext(‘/path/to/somefile.ext’) >>> filename ‘/path/to/somefile’ >>> file_extension ‘.ext’ Unlike most manual string-splitting attempts, os.path.splitext will correctly treat /a/b.c/d as having no extension instead of having extension .c/d, and it will treat .bashrc as having no extension instead of having … Read more

How to get a file’s extension in PHP?

People from other scripting languages always think theirs is better because they have a built-in function to do that and not PHP (I am looking at Pythonistas right now :-)). In fact, it does exist, but few people know it. Meet pathinfo(): $ext = pathinfo($filename, PATHINFO_EXTENSION); This is fast and built-in. pathinfo() can give you … Read more