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

Re: Regex to extract last 3 components of filename

by 1nickt (Canon)
on May 04, 2021 at 21:46 UTC ( [id://11132043]=note: print w/replies, xml ) Need Help??


in reply to Regex to extract last 3 components of filename

Because your regexp is greedy. See also Breaking file path into segments, perlretut.

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Regex to extract last 3 components of filename
by Fletch (Bishop) on May 04, 2021 at 22:51 UTC

    Started to reply with a similar Path::Tiny invocation then read what you'd linked so . . . foo. Instead, File::Spec(::Functions):

    $ perl -MFile::Spec::Functions=splitdir -E '@p = splitdir( "/x/y/z/a/b +/c/d/e.f" );say join( qq{\n}, @p[-3,-2,-1] )' c d e.f

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-03-29 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found