in reply to Canonical regexp for urls beginning with http://

Given a file named "example"

which contains the line:

http://cisco.com You've got a match!

this:
#!/usr/local/bin/perl -w use strict; my $file = "/export/home/ssesar/example"; my $line; open (FILE, $file) || die "\n$!"; while ($line = <FILE>) { chomp $line; if ($line =~ m/^http\:\/\//) { print "line = $line\n"; } else { print "Sorry, dude\n"; } }
works.

Replies are listed 'Best First'.
Re: Re: Canonical regexp for urls beginning with http://
by merlyn (Sage) on Feb 22, 2001 at 02:52 UTC
    As long as that's your only line. You could have just said:
    @ARGV = qw(/export/home/ssesar/example); print "line = $_" for <>;
    for the accuracy you give. See the other answers in this thread for things which actually detect valid URLs, and reject bad ones.

    -- Randal L. Schwartz, Perl hacker

      Thanks! Much easier!