Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

regular expression for workdir

by azaria (Beadle)
on Jan 01, 2006 at 13:59 UTC ( #520237=perlquestion: print w/ replies, xml ) Need Help??
azaria has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I would like to find 2 sequence directory names appears in a given pathname after a given magic word. is there any sophisticate regular expression for that (no spilt method) e.g: $magic_word = "azaria"; $path = "/net/moon/slice1/azaria/bin/files/perl"; then I want to get "bin/files" since those 2 directories follow the magic word "azaria" Please advice, azaria

Comment on regular expression for workdir
Re: regular expression for workdir
by wfsp (Abbot) on Jan 01, 2006 at 14:27 UTC
    One way:

    $path =~ m|$magic_word/([^/]+/[^/]+)/|; print "$1\n";
      Thanks you all, this is exactly what i need !!!!
Re: regular expression for workdir
by holli (Monsignor) on Jan 01, 2006 at 14:41 UTC
    Another way:
    print substr($path, index($path, $magic_word)+length($magic_word)+1);


    holli, /regexed monk/
Re: regular expression for workdir
by turo (Friar) on Jan 01, 2006 at 15:12 UTC

    TIMTOWTDI :-)

    print ((split q|/|,$path)[-1]);

    regards

    turo

    perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'
Re: regular expression for workdir
by Dietz (Curate) on Jan 01, 2006 at 15:37 UTC

    This would be more straightforward than the other suggestions:

    my ($subpath) = $path =~ m|$magic_word/(.*)/.*|; print $subpath, $/;

    Update:

    Rereading the question, I misinterpreted it, since my solution will gather all directories after the magic word.
    Go with wfsp's solution which fits in perfectly.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-07-24 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls