use strict; use warnings; my $path_head = _get_first_3( '/a/b/c/d/e/f' ); sub _get_first_3 { my ($path) = @_; my $path_part = qr{ [^/]+ }x; # whatever char except slash my $path_head_regex = qr{ ( \A # beginning of string ( / $path_part) {3} ) # /three/part/parts here }x; my ($head) = ($path =~ m{ $path_head_regex }x); return $head; }
In reply to Re^2: Extract portion of string based on string separator
by Krambambuli
in thread Extract portion of string based on string separator
by linuxfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |