in reply to Re: Extract portion of string based on string separator
in thread Extract portion of string based on string separator
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Extract portion of string based on string separator
by linuxfan (Beadle) on Apr 26, 2007 at 16:25 UTC |