Reputation: 33
I'd like to regex capture in Perl, all characters after the second occurrence of the /
character.
using the the example:
/en-us/hello/world/newyork.html
I'd like to be able to capture:
hello/world/newyork.html
I tried:
^(?:[^\/]*\/){2}([^\/]*)
Only captures hello
as group 1.
Upvotes: 1
Views: 159
Reputation: 23347
Try this one:
\/[^\/]+\/(.*)
Explanation:
\/[^\/]+\/
you first match everything till the second /
:
\/
the first slash[^\/]+
one or more of chars that are not a slash(.*)
the substring you need is in the capturing groupUpvotes: 3
Reputation: 39158
Is this URI parsing? It looks like URI parsing.
use URI qw();
my $u = URI->new;
$u->path('/en-us/hello/world/newyork.html');
my @s = $u->path_segments;
print join '/', @s[2..@s-1];
Upvotes: 0