Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: extract file name from path

by TJPride (Pilgrim)
on Sep 11, 2013 at 19:19 UTC ( #1053551=note: print w/ replies, xml ) Need Help??


in reply to extract file name from path

We can probably assume the pattern will always start with a / (since that's part of the path) and end with some sort of .ext:

my $line = 'root 30145 1 0 Jan30 ? 00:09:01 /root/java/app/java_app_1R +ule_java_app_2Rule.java --javaproc'; if ($line =~ m|/([^/]*?)\.[a-z0-9]+|) { print "$1\n"; }


Comment on Re: extract file name from path
Download Code
Replies are listed 'Best First'.
Re^2: extract file name from path
by Laurent_R (Monsignor) on Sep 12, 2013 at 07:52 UTC

    I think that you need to add the underscore ('_') to the character class in your regex.

    Update: I read too quickly. Reading again your regex, no, there is no need to add the underscore, since this character class is aimed at matching the final "java" extension.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2015-07-29 04:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls