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