Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Regex to extract last 3 components of filename

by choroba (Cardinal)
on May 04, 2021 at 21:51 UTC ( [id://11132044]=note: print w/replies, xml ) Need Help??


in reply to Regex to extract last 3 components of filename

If you don't want to match a slash, tell Perl about it:
m{/([^/]*?)/([^/]*?)/([^/]*?)\.([a-z0-9]+?)$}

The problem can be solved using split in a much cleaner way:

my @parts = (split m{/}, '/x/y/z/a/b/c/d/e.f'); splice @parts, 0, -3; push @parts, split /\./, pop @parts; print "<$_>" for @parts;

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132044]
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 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found