in reply to Re: Regexp match filename, exclude path
in thread Regexp match filename, exclude path

Right. I realize why the regexp I tried doesn't work. The solution can't be anything except a backslash, it has to be something like the last set of characters that isn't preceded by a backslash. I realize I could do this with a module, splitting on backslashes then taking the last element, etc., but I want to do it with a regexp if I can.
  • Comment on Re^2: Regexp match filename, exclude path

Replies are listed 'Best First'.
Re^3: Regexp match filename, exclude path
by Corion (Patriarch) on Oct 04, 2008 at 17:58 UTC

    I'm not sure what you mean by

    The solution can't be anything except a backslash, it has to be something like the last set of characters that isn't preceded by a backslash.

    The following will match the last sequence of non-backslash characters in your string, which is what you seem to want:

    m![^\\]+\.pdf$!;

    Anchoring the match makes sure you get the filename path, and the character set negation makes sure you get nothing with a backslash in it.