A
adamomitcheney
Hi All,
Apologies in advance if this is a dumb question ("There are no stupid
questions, but there are loads of inquisitive idiots")...
I wanted a regular expression to seperate a filename from a full path
(UNIX). I came up with the following:
$target =~ m%(.+/)(.+)%;
$targetpath = $1;
$targetfile = $2;
Actually, I expected that not to work; but it does, apparently
perfectly. I thought it would fail because I thought the $1 portion of
the regexp would process $target until it found the leftmost '/' and
then stop, leaving everything else to the $2 part. Why am I wrong? Am I
just feeding it a particularly restrictive set of cases?
What regular expression could I use if I wanted to split a UNIX path
into the bottom level (that is, closest to root) directory and the rest
of the path?
Thanks for your indulgence.
Adam...
Apologies in advance if this is a dumb question ("There are no stupid
questions, but there are loads of inquisitive idiots")...
I wanted a regular expression to seperate a filename from a full path
(UNIX). I came up with the following:
$target =~ m%(.+/)(.+)%;
$targetpath = $1;
$targetfile = $2;
Actually, I expected that not to work; but it does, apparently
perfectly. I thought it would fail because I thought the $1 portion of
the regexp would process $target until it found the leftmost '/' and
then stop, leaving everything else to the $2 part. Why am I wrong? Am I
just feeding it a particularly restrictive set of cases?
What regular expression could I use if I wanted to split a UNIX path
into the bottom level (that is, closest to root) directory and the rest
of the path?
Thanks for your indulgence.
Adam...