Don't ask to ask, just ask | |
PerlMonks |
Re: Finding a extentionby elusion (Curate) |
on Oct 05, 2002 at 16:02 UTC ( [id://203047]=note: print w/replies, xml ) | Need Help?? |
If you want to get the extension, you can do this: $ext =~ s/^.+(\.\w+)$/$1/; That substitutes the whole string with the last dot and what comes after. What behavior do you want with "foo.tar.gz"? The above regex will replace it with ".gz". If you want ".tar.gz", you should use $ext =~ s/^.+?(\.[\w\.]+)$/$1/; which searches for as little as possible in front, followed by a dot and one or more alphanumerics or dots. This can cause problems with directories that have dots in them though. If that becomes a problem, you will need to test for "/" in the regex. Hope this helps, elusion : http://matt.diephouse.com
In Section
Seekers of Perl Wisdom
|
|