[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [MacPerl] Easy regex?



I see that the original poster is happy with the responses we've given
him, but after reviewing them, it seems to me that no one mentioned the
simplest and most straight-forward. No need for back references or fancy
function calls, just

#############
#!perl

$orig_path =
"server.mydomain.de/directory1/directory2/irritating_filename.pl";

$orig_path =~ m#.*/#;

print "$&\n";

exit(0);
#############

which yields:

server.mydomain.de/directory1/directory2/

Remember that '*' is greedy. It matches the whole string. Perl starts
looks for a '/' starting from the last 'l' in the string and works
backward from right to left until it finds one. The special Perl
variable '$&', which I'm using in the print statement above, holds the
whatever was matched in the last regular expression.

When you hear hooves, think horses, not zebras.

Robert




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch