Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

RegEx is required for the below pattern

by asab (Sexton)
on Sep 28, 2011 at 14:00 UTC ( #928330=perlquestion: print w/replies, xml ) Need Help??

asab has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I am looking for regex for the below experession.

 /tom/john/jones/fredy/sam-joe/Install-xyz-opq.zip

I want extract the Install-xyz-opq.zip from the above pattern

conditions are number of directories from / to Install-xyz-opq.zip is always variable. directory names may contain - and other allowed special character in linux. but the pattern always ends with Install-xyz-opq.zip. can you guys please provide me with this RegEx.

Thanks in advance

asab

Replies are listed 'Best First'.
Re: RegEx is required for the below pattern
by toolic (Bishop) on Sep 28, 2011 at 14:22 UTC
    Sounds like a job for File::Basename...
    use warnings; use strict; use File::Basename; my $path = '/tom/john/jones/fredy/sam-joe/Install-xyz-opq.zip'; my $file = basename($path); print "$file\n"; __END__ Install-xyz-opq.zip
Re: RegEx is required for the below pattern
by ww (Archbishop) on Sep 28, 2011 at 14:15 UTC
    Someone may "provide" you with your regex; it would be a better deal at this end if you provided the provider with your paycheck.

    Alternately, you may wish to read the Tutorials on regexen here... and the docs on the topic which live right in your own computer. See perldoc perldoc for details... and please read On asking for help and How do I post a question effectively? before asking the Monks to do your work.

Re: RegEx is required for the below pattern
by dreadpiratepeter (Priest) on Sep 28, 2011 at 14:12 UTC
    Perl Monks is not a code writing service. If you show that you have put in the effort you will have a much better chance of getting help. I would suggest posting what you have tried, and where you are having trouble


    -pete
    "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
Re: RegEx is required for the below pattern
by Ratazong (Monsignor) on Sep 28, 2011 at 14:13 UTC
    Have you thought about using split (using / as the delimiter) instead of a regex?
Re: RegEx is required for the below pattern
by hbm (Hermit) on Sep 28, 2011 at 14:13 UTC

    Like this?

    my $file = '/tom/john/jones/fredy/sam-joe/Install-xyz-opq.zip'; $file =~ s|^.*/||; # delete up to and including the rightmost '/' if ($file eq "Install-xyz-opq.zip") { ...
Re: RegEx is required for the below pattern
by rnaeye (Friar) on Sep 28, 2011 at 14:45 UTC

    You can start with File::Basename module.

      All, thanks a lot for the replies

      Yes from next time i will be prepared little better

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2022-06-28 21:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (92 votes). Check out past polls.

    Notices?