Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
When you match your url against $RE{URI}{HTTP}{-keep}, what you want will be in $3, 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__
prints:
http://yahoo.co.uk/notfound.html => yahoo.co.uk http://yahoo.co.uk:80/notfound.html?fn=john&ln=doe => yahoo.co.uk http://yahoo.co.uk/ => yahoo.co.uk http://yahoo.co.uk => yahoo.co.uk yahoo.co.uk/notfound.html => No match yahoo.co.uk => No match potato://yahoo.co.uk => No match http://yahoo.co.uk:80/notfound.html?fn=john&ln=doe => http yahoo.co.uk 80 /notfound.html?fn=john&ln=doe notfound.html?fn=john&ln=doe notfound.html fn=john&ln=doe
See Regexp::Common and Regexp::Common::URI::http.

Update: Added <readmore>


In reply to Re: Extracting a domain name from a url by fenLisesi
in thread Extracting a domain name from a url by abachus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found