On Wed, 7 Jun 2006, darren kirby wrote:

> Hello all,
>
> I want to split a filename into it's root and extension, ie:
> someFileName.txt = 'someFileName' and 'txt'
>
> This is simple enough with string.split(), but what if the file has more than
> one period in it? I have worked around this by doing:
>
> filename = "some.file.name.txt"
> temp = filename.split(".")
> type = temp.pop
> fileroot = temp.join(".")
>
> I was wondering though if instead of the temp variable I could just do:
>
> 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?
>
> Thanks,
> -d



   jib:~ > ruby -e'  p "bar.txt".split( %r/\.([^\.]+)$/ )  '
   ["bar", "txt"]



   jib:~ > ruby -e'  p "/foo/bar.txt".split( %r/\.([^\.]+)$/ )  '
   ["/foo/bar", "txt"]


-a
-- 
suffering increases your inner strength.  also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama