Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Finding a extention

by elusion (Curate)
on Oct 05, 2002 at 16:02 UTC ( #203047=note: print w/replies, xml ) Need Help??

in reply to Finding a extention

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 :

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://203047]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2019-07-18 11:49 GMT
Find Nodes?
    Voting Booth?

    No recent polls found