#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Extract_file_extension
#

func extension(filename) {
    filename.match(/(\.[a-z0-9]+)\z/i).to_s
}

var files = [
    'http://example.com/download.tar.gz',
    'CharacterModel.3DS',
    '.desktop',
    'document',
    'document.txt_backup',
    '/etc/pam.d/login',
]

var exts = []

files.each {|f|
    exts << (var e = extension(f))
    printf("%-36s -> %-11s\n", f.dump, e.dump)
}

assert_eq(exts, ['.gz', '.3DS', '.desktop', '', '', ''])
