See code:
var file1 = \"50.xsl\"; var file2 = \"30.doc\"; getFileExtension(file1); //returns xsl getFileExtension(file2); //returns doc function getFileExt
function getFileExtension(filename) { var ext = /^.+\.([^.]+)$/.exec(filename); return ext == null ? "" : ext[1]; }
Tested with
"a.b" (=> "b") "a" (=> "") ".hidden" (=> "") "" (=> "") null (=> "")
Also
"a.b.c.d" (=> "d") ".a.b" (=> "b") "a..b" (=> "b")