DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Return The Extension From A File Name

  • submit to reddit
        // Return the extension from a file name



Snippets Manager replied on Fri, 2009/02/27 - 3:07pm

file_ending = filename[/(?:.*\.)(.*$)/, 1] Dont capture everything in the first brackets .. everything before the last dot . and return the first(second in ary) component of the MatchData. Play with it at rubular:

Snippets Manager replied on Mon, 2012/05/07 - 1:27pm