I personally prefer to split the string by .
and just return the last array element :)
var fileExt = filename.split('.').pop();
If there is no .
in filename you get the entire string back.
Examples:
'some_value' => 'some_value'
'.htaccess' => 'htaccess'
'../images/something.cool.jpg' => 'jpg'
'http://www.w3schools.com/jsref/jsref_pop.asp' => 'asp'
'http://stackoverflow.com/questions/680929' => 'com/questions/680929'