Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Regexp question...
June 13, 2005, 8:40 am
rate this thread
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.
Re: Regexp question...
firstname.lastname@example.org wrote in
You do not need the full regex machinery to do accomplish such a
task. In addition, using File::Basename is more appropriate than
rolling your own in this case. See
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW: