On Mon, Jul 20, 2009 at 04:52, <peter-mail...@web.de> wrote: > Hello, > > I've to cut off parts of an url like > '/something_variable_1/something_constant/something_variable_2/something_variable_3/filename' > > The result should be 'something_variable_3/filename' > > To cut off the part '/something_variable_1/something_constant' works with the > regular expression 's/^.*\/something_constant\///' > > But I dont manage to cut of the 'something_variable_2' part. I tried > combinations of .*?{}() but the result is either no cut > ('something_variable_2/something_variable_3/filename') or only the filename. snip
TIMTOWTDI: #!/usr/bin/perl use strict; use warnings; my $s = '/something_variable_1/something_constant/something_variable_2/something_variable_3/filename'; my $one = join "/", (split "/", $s)[-2, -1]; my ($two) = $s =~ m{/([^/]+/[^/]+)$}; my $three = reverse ((reverse $s) =~ m{^(.*?/.*?)/}); print map { "$_\n" } $one, $two, $three; -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/