views:

90

answers:

1

I'm looking for a REGEX to obtain a files extention.

Given examples like:

modocument.doc
modocument.docx
dasddsa.pdf
kdsksdklsadklasdklads.png
ads123.jpg

I need a REGEX that provides the 3-4 char extention, but isn't fooled by things like:

asdadsasdads.jpg.png

And only gets PNG as seen above. thxs

+12  A: 

I think ListLast would do a better job for you:

<cfset FileExt=ListLast(YourFilename,".")>
Gert G
This will also be much faster than using a regex.
Ben Doom
To expand on Ben's comment - regexes don't work backwards, so they have to scan the whole string, where as ListLast will start at the end and go back, only looking at a handful of chars.
Peter Boughton
Be sure to keep in mind wether the file even has an extension.
Tyler Clendenin