0

Presently I'm getting a list of URLs from a text file like so:

perl -MRegexp::Common=URI -nE 'say $& while /$RE{URI}{HTTP}{-scheme => "https?"}/g' urls.txt

And am wondering how to get only the host field. The package documentation mentions a -keep parameter, but the source implementation does not show it as being available.

I'm aware that my desired output can be achieved by piping the output to other programs and handling it, but is it possible to achieve what I want in this command?

1 Answer 1

1

but the source implementation does not show it as being available.

It is not implemented in Regexp::Common::URI but inherited from Regexp::Common. And using this parameter works as documented:

perl -MRegexp::Common=URI -nE \
  'say $3 while /$RE{URI}{HTTP}{-scheme => "https?"}{-keep}/g' \
  urls.txt
2
  • Thanks, that works! As a side question if you wouldn't mind helping, is there any way to get capture the $hostname expression from the RFC2396 specification? The $host captures both a domain or IPv4 address.
    – T145
    Jan 4 at 6:30
  • 1
    @T145: I don't see an obvious way with the module to get only hostname not IPv4. Jan 4 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.