in reply to Regular Expression Help

/.*\/(.*?)$/ will do the trick, I think. Regular expression greed will consume everything up until the last '/' with the first .* and leave only the last subdir.

Replies are listed 'Best First'.
Re^2: Regular Expression Help
by Anonymous Monk on Nov 18, 2005 at 20:09 UTC
    It doesn't work.
      Fletch is right -- use File::Basename -- but in the more general case of finding the last token in a string, that regex ought to work:
      #!/usr/local/bin/perl use strict; my $string = '/one/two and three/and four / and five'; if ($string =~ /.*\/(.*?)$/) { print "Last token: $1\n"; }
      Or you could always split on your token separator and grab the last element in the resulting array.