in reply to Pattern matching

Definitely go with File::Basename, and i like ikegami's solution above better than this one, but to directly translate your question of "find the last occurrence of \\ and then give me everything from that match to the end of the string" into a regex, i offer this:
$s =~ /\\(.*?)$/; # UPDATE: THIS IS WRONG!!! my $endPart = $1;
Four parts: 1) matches a (escaped) backslash 2) anchor to the end of the string with $ 3) capture all the stuff ( .* ) inbetween by surrounding w/parens 4) make that cature non-greedy with the ? -- this way it implicitly makes the \\ be the furthest one to the right in the string.
Update: OOPS. As pointed out, that greedy usage is wrong. I would just stick with the abover method of the non-backslash character class. Though this will work if matching the beginning of the string like /^(.*?)\\/
Update 2: I think what i originally intended was /.+\\(.*?)$/

As for grouping and back matching in general, the Tutorials and perldoc perlre and starting places.
Quick & dirty grouping overview: Basically the way grouping works is anything you put in parens will get captured, and the first capture will be stored in $1, the second in $2, and so on.
my $s = "This is a blurb"; if( $s =~ /(\S+)\s\S+\s\S+\s(\S+)/ ){ print "$1:$2"; # This:blurb }
Two quick notes: A) Always make sure the regex matched successfully before using $1, etc. B) You can prevent parens from capturing by using ?: like this: /(?:blah)/

Replies are listed 'Best First'.
Re^2: Pattern matching
by hv (Prior) on Jun 08, 2005 at 08:46 UTC

    $s =~ /\\(.*?)$/;

    ... 4) make that cature non-greedy with the ? -- this way it implicitly makes the \\ be the furthest one to the right in the string.

    This is incorrect: greedy or non-greedy, the regexp engine will always try to match the string at a given location any way it can before it proceeds to try at the next location. This will therefore always match the first "\\", not the last.

    See How will my regular expression match? for more information.

    Hugo