Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Detecting URLs with URI

by Mr. Muskrat (Canon)
on May 26, 2016 at 20:21 UTC ( #1164226=note: print w/replies, xml ) Need Help??


in reply to Detecting URLs with URI

  1. Pick a suitable default and use it if the URL doesn't contain a scheme.
  2. Allow URI->canonical to lowercase it.
Example code below:

#!/bin/env perl use strict; use warnings; use URI; for my $search ('http://www.foo.com', 'https://www.foo.com', 'www.foo. +com', 'WWW.FOO.COM', 'ftp://www.foo.com') { my $url = $search; # we can't modify $search directly $url = 'http://' . $url unless $url =~ m!^\w+://!; # If there isn't +a schema, add http:// my $uri = URI->new($url)->canonical->as_string; print "$search => $uri\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1164226]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2018-02-21 12:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (279 votes). Check out past polls.

    Notices?