This is really more of a job for the File::Basename module than a job for a goofy regexp. With the module you could just do this:
use File::Basename;
my $dirname = dirname ("lib/this/that/other.txt");
However, if you're sure that the path delimeter is a slash (either forward or backslash), and that the slash characters won't comprise part of a name, you could probably get away with a regexp like this:
($path, $filename) = $fullpath =~ m/^(.*[/\\])([^/\\]+)/;
Since it's easy to goof the Regexp (and mine is untested), you're better off using the module mentioned above. It's a lot better to rely on good tested code than a homebrewed complicated regexp, most of the time.
Update: I wanted to note that File::Spec and File::Basename are both part of the core Perl distribution, and thus, probably came standard with your implementation of Perl.
|