From: cdc@...2go.com (Cliff Cyphers) Date: 2006-06-07T10:40:56+09:00 Subject: Re: regex for splitting filenames --3MwIy2ne0vdjdPXF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 07, 2006 at 10:30:23AM +0900, darren kirby wrote: > Hello all,=20 >=20 > I want to split a filename into it's root and extension, ie: > someFileName.txt =3D 'someFileName' and 'txt' >=20 > This is simple enough with string.split(), but what if the file has more = than=20 > one period in it? I have worked around this by doing: >=20 > filename =3D "some.file.name.txt" > temp =3D filename.split(".") > type =3D temp.pop > fileroot =3D temp.join(".") >=20 > I was wondering though if instead of the temp variable I could just do: >=20 > fileroot, type =3D filename.split(/regex here?/) >=20 > I cannot find a way to write a regex that only matches the last period in= the=20 > filename. Is there an elegant way to do this? >=20 > Thanks, > -d > --=20 > darren kirby :: Part of the problem since 1976 :: http://badcomputer.org > "...the number of UNIX installations has grown to 10, with more expected.= =2E." > - Dennis Ritchie and Ken Thompson, June 1972 base =3D ("#{filename}"[0..("#{filename}".rindex('.')-1)]) --3MwIy2ne0vdjdPXF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFEhi6kpXfXwRYlDA0RAhgUAJkBcaDGRqNMCirRjhgd3a4OhljuFACfaJwD TVhCdBowEIbi89Y4Jl4gnlA= =laqh -----END PGP SIGNATURE----- --3MwIy2ne0vdjdPXF--