| Home » Faqs » Regexp » Regexp url |
You need a regular expression to match urls in some text.
Don't reinvent the wheel. A module called Regexp::Common contains many, many common regular expression - including those for matching urls.
#!/usr/bin/perl
use strict;
use warnings;
use Regexp::Common qw(URI);
my @urls;
while (<>) {
# Provide a way out
last if ($_ eq "\n");
# Match URLs
push (@urls, /$RE{URI}{HTTP}/g);
}
Read through the Regexp::Common documentation for further common regular expressions:
perldoc Regexp::Common
For more general regular expression information, see:
perldoc perlretut
perldoc perlre