function extName(url) { var m = /\.([^\/.#?]+)(?:\?|#|$)/.exec(url); return m ? m[1] : ''; } alert(extName('http://foo.com/my.gif.jpeg?foo=1'));