in reply to regex help

Hello vijesh,

McA is correct, when dealing with filenames and paths a dedicated module will provide a safer and more portable solution than a hand-written regex. But if you still want to use a regex, try this:

17:12 >perl -wE "my $s = q{/fold1/fold2/fold3/file.pl}; print $1, qq{\ +n} if $s =~ m{^(.+?)[^/]+$}; /fold1/fold2/fold3/ 17:16 >

This works because the second quantifier is greedy but the first is not.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: regex help
by vijesh (Novice) on Oct 20, 2014 at 08:11 UTC

    Hello Athanasius, Thanks for regex. As you said, McA's suggestion also helps. I shall go with Basename api's. -Thanks and Regds, Vijesh