, which you should extract immediately after the match. This sample code:
use strict;
use warnings;
use Regexp::Common qw(URI);
my $URI = $RE{URI}{HTTP}{-keep};
my @uris = (
'http://yahoo.co.uk/notfound.html',
'http://yahoo.co.uk:80/notfound.html?fn=john&ln=doe',
'http://yahoo.co.uk/',
'http://yahoo.co.uk',
'yahoo.co.uk/notfound.html',
'yahoo.co.uk',
'potato://yahoo.co.uk',
);
## Extract the host from the sample urls above
for my $uri (@uris) {
my (
$whole, $scheme, $host, $port,
$path_q_slash, $path_q_noslash, $path_noq_noslash,
$query,
)
= ($uri =~ $URI);
if (defined $whole) {
printf "%-50s => %s\n", $whole, $host;
}
else {
printf "%-50s => No match\n", $uri;
}
}
##
## An example with all the pieces:
## 'http://yahoo.co.uk:80/notfound.html?fn=john&ln=doe'
##
my $uri = $uris[1];
my ($whole, @bits) = ($uri =~ $URI);
printf "\n%s =>\n %s\n", $whole, (join qq(\n ), @bits );
__END__