From: Austin Ziegler Date: 2006-06-07T21:04:53+09:00 Subject: Re: regex for splitting filenames On 6/6/06, Matthew Smillie wrote: > On Jun 7, 2006, at 2:54, Austin Ziegler wrote: > > On 6/6/06, darren kirby wrote: > >> fileroot, type = filename.split(/regex here?/) > > > >> I cannot find a way to write a regex that only matches the last > >> period in the > >> filename. Is there an elegant way to do this? > > > > ext = File.extname(filename) > > file = File.basename(filename, ext) > > Equivalent, but I like the semantics a little better > > require 'pathname' > f = Pathname.new(filename) > f.basename > f.extname > pathname is very handy - see the standard library docs: http://ruby- > doc.org/stdlib/libdoc/pathname/rdoc/index.html I think you mean f.basename(f.extname) for the basename without the extensions. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca