Hello,
Here is a simple regular expression that isn't working quite like I would expect. I think I know what's going on, but I'm not sure if I like it
Notice that I'm grabbing as little as possible with the .*?, and I'm anchoring to the right end of the string. Since it's grabbing as little as possible with a "/" just to the left, I thought this would print just "file.txt". However, it's printing "hello/this/is/my/folder/file.txt".
I think what's happening is its finding the "/" first, then attempting to find a .*? match after that. Shouldn't Perl keep scanning to see if it can reduce the .*? any more?
Here is a simple regular expression that isn't working quite like I would expect. I think I know what's going on, but I'm not sure if I like it
Code:
my $string = "/hello/this/is/my/folder/file.txt";
$string =~ /\/(.*?)$/;
print $1;
Notice that I'm grabbing as little as possible with the .*?, and I'm anchoring to the right end of the string. Since it's grabbing as little as possible with a "/" just to the left, I thought this would print just "file.txt". However, it's printing "hello/this/is/my/folder/file.txt".
I think what's happening is its finding the "/" first, then attempting to find a .*? match after that. Shouldn't Perl keep scanning to see if it can reduce the .*? any more?