regular expression for workdir
azaria
created: 2006-01-01 08:59:11
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
Re: regular expression for workdir
created: 2006-01-01 09:27:39
One way:

$path =~ m|$magic_word/([^/]+/[^/]+)/|;
print "$1\n";
Re^2: regular expression for workdir
created: 2006-01-01 12:48:42
Thanks you all, this is exactly what i need !!!!
Re: regular expression for workdir
created: 2006-01-01 09:41:58
Another way:
print substr($path, index($path, $magic_word)+length($magic_word)+1);


holli, /regexed monk/
Re: regular expression for workdir
created: 2006-01-01 10:12:34

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
created: 2006-01-01 10:37:48

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.

perlmonks.org content © perlmonks.org and azaria, Dietz, holli, turo, wfsp

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03