Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

perl module to determine if a URL is valid?

by keiusui (Monk)
on Sep 20, 2009 at 18:49 UTC ( [id://796405]=perlquestion: print w/replies, xml ) Need Help??

keiusui has asked for the wisdom of the Perl Monks concerning the following question:

Hello, is there a standard or common Perl module used to determine if a URL is valid? I do not need to check whether the URL actually exists; I just need to check whether a URL entered by a user is a valid URL string or not.

For example, the Email::Valid module does a great job of simply checking whether a string is in valid e-mail format.

Thanks!

  • Comment on perl module to determine if a URL is valid?

Replies are listed 'Best First'.
Re: perl module to determine if a URL is valid?
by moritz (Cardinal) on Sep 20, 2009 at 18:55 UTC
    I use Regexp::Common::URI for finding URLs, and it can also validate URLs.

    It comes with two caveats though: It doesn't understand https (only http), so I do something like this in my code:

    use Regexp::Common qw /URI/; my $re = $RE{URI}{HTTP}; $re =~ s/http/https?/g;

    The second caveat is that it doesn't understand anchors (ie the part after a # pound sign).

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: perl module to determine if a URL is valid?
by ccn (Vicar) on Sep 20, 2009 at 18:57 UTC
    use Regexp::Common qw /URI/; while (<>) { /$RE{URI}{HTTP}/ and print "Contains an HTTP URI.\n"; }
      You can also use
      $regexp = qr($RE{URI}{HTTP}{-scheme=>qr/https?/}{-keep});
Re: perl module to determine if a URL is valid?
by Anonymous Monk on Sep 20, 2009 at 19:37 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://796405]
Approved by Joost
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-18 22:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found