Reputation: 7
my $path= "/tmp/main/store/important/file/log"; ##string
$path =~ m/file/;
print "$&/$'\n";
I want to capture file/log/.*/.*/ .. . . ..
And the path may vary, any other way to solve this?
Thanks guys
Upvotes: 0
Views: 46
Reputation: 149736
Just use greedy matching (.*
):
my $path= "/tmp/main/store/important/file/log";
my ($tail) = $path =~ m!(/file/.*)!;
print $tail; # /file/log
Here I also use a custom delimiter for the m//
operator to avoid escaping slashes.
Upvotes: 2