in reply to R.Exp. Matching from the Right

You really want File::Basename, which is made for file/directory manipulation.

But for regular expressions, you want what is called an anchor. There are two (well, technically four) of them: ^ anchors the match to the start of the string, and $ anchors it to the end (see perlre). So your problem could be solved by:

my $file = "c:/progra~1/apache~1/apache2/cgi-bin/test/new/Feb23-2006_0 +_test_error.txt"; if ($file =~ m!^(.*)/(\w+\.txt)$!) { print "Found $1 - $2\n"; } else { print "No match found for '$file'\n"; };

Replies are listed 'Best First'.
Re^2: R.Exp. Matching from the Right
by ikegami (Patriarch) on Feb 23, 2006 at 18:21 UTC

    There are five anchors:
    without m with m
    Start of string \A and ^ \A
    Start of line ^
    End of string or before \n at end of string \Z and $ \Z
    End of line or before \n at end of line $
    End of string \z \z