Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Finding a extention

by elusion (Curate)
on Oct 05, 2002 at 16:02 UTC ( [id://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 : http://matt.diephouse.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found