🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #29482

Re: heuristics for matching URLs in text/plain

#29482
From: Terje Bless
Date: Wed, 15 Jan 1997 00:00
304 lines
15728 bytes
In article <32D945A2.1D70@netscape.com>,
    Jamie Zawinski <jwz@netscape.com> wrote:

>FYI, here's what Netscape does to match URLs in arbitrary text.  It's
>far from perfect, but it seems to work pretty well most of the time.
>
>In our code, we don't actually use regexp matching to do this (it's
>coded as a loop) so the patterns below are approximate.

(This article is actually contrary to my strong belief that HTML (and
similar crud) has no place on USENET, but it's an actuall implementation
rather than opinionated commentary which seems most prevalent in this
thread(s).)

Here's an interesting little tidbit (actually it's a *huge* tidbit, but
let's not nitpick ;D) from comp.lang.perl.misc:



Date: Tue, 19 Nov 1996 03:59:38 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: regx for url
Newsgroups: comp.lang.perl.misc
X-Http: http://www.ny.fnx.com/abigail/
Message-Id: <E13n3E.Jv9@news2.new-york.net>

On Mon, 18 Nov 1996 04:09:58 GMT, Lyn A Headley wrote in comp.lang.perl.misc:
++ hi,
++ 
++ I've searched CPAN pretty hard, but can't seem to find
++ a regx which matches urls.  can anyone point me to it? 
++ (or better yet, post the regx :) ).

Post the regexp? Are you sure? It's pretty long, over 8k.

Ok, here it goes:
(?:http://(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:[a-z])|(?:[A-Z]))|\d)(?:(?:(?:(?:
[a-z])|(?:[A-Z]))|\d)|-)*(?:(?:(?:[a-z])|(?:[A-Z]))|\d))|(?:(?:(?:[a-z])|(?:
[A-Z]))|\d))\.)*(?:(?:(?:(?:[a-z])|(?:[A-Z]))(?:(?:(?:(?:[a-z])|(?:[A-Z]))|\
d)|-)*(?:(?:(?:[a-z])|(?:[A-Z]))|\d))|(?:(?:[a-z])|(?:[A-Z])))))|(?:(?:(?:\d
+)\.(?:\d+)\.(?:\d+)\.(?:\d+)))))(?::(?:(?:\d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Z]))(?:(?:(?:(?:[a-z])|(?:[A-Z]))|\d)|-)*(?:(?:(?:[a-z]
)|(?:[A-Z]))|\d))|(?:(?:[a-z])|(?:[A-Z])))))|(?:(?:(?:\d+)\.(?:\d+)\.(?:\d+)
\.(?:\d+)))))(?::(?:(?:\d+)))?))(?:/(?:(?:(?:(?:(?:[a-z])|(?:[A-Z]))|(?:\d)|
(?:[$_.+-])|(?:[!*'(),]))|(?:%(?:[\dA-Fa-f])(?:[\dA-Fa-f]))|(?:[;/?:@&=]))*))
?)))


Perhaps you prefer a slowly build up? Here's a little program
constructed by turning the pseudo BNF of RFC 1738 into Perl
regexps:


#!/usr/local/bin/perl -w

use Carp;
use strict;

# Be paranoid about using grouping!

my $lowalpha       =  '(?:[a-z])';
my $hialpha        =  '(?:[A-Z])';
my $alpha          =  "(?:$lowalpha|$hialpha)";
my $digit          =  '(?:\d)';
my $safe           =  '(?:[$_.+-])';
my $extra          =  '(?:[!*\'(),])';
my $national       =  '(?:[{}|\\\\^~\[\]`])';
my $punctuation    =  '(?:[<>#%"])';
my $reserved       =  '(?:[;/?:@&=])';
my $hex            =  '(?:[\dA-Fa-f])';
my $escape         =  "(?:%$hex$hex)";
my $unreserved     =  "(?:$alpha|$digit|$safe|$extra)";
my $uchar          =  "(?:$unreserved|$escape)";
my $xchar          =  "(?:$unreserved|$escape|$reserved)";
my $digits         =  '(?:\d+)';
my $alphadigit     =  "(?:$alpha|\\d)";

# URL schemeparts for ip based protocols:
my $urlpath        =  "(?:$xchar*)";
my $user           =  "(?:(?:$uchar|[;?&=])*)";
my $password       =  "(?:(?:$uchar|[;?&=])*)";
my $port           =  "(?:$digits)";
my $hostnumber     =  "(?:$digits\\.$digits\\.$digits\\.$digits)";
my $toplabel       =  "(?:(?:$alpha(?:$alphadigit|-)*$alphadigit)|$alpha)";
my $domainlabel    =  "(?:(?:$alphadigit(?:$alphadigit|-)*$alphadigit)|" .
                      "$alphadigit)";
my $hostname       =  "(?:(?:$domainlabel\\.)*$toplabel)";
my $host           =  "(?:(?:$hostname)|(?:$hostnumber))";
my $hostport       =  "(?:(?:$host)(?::$port)?)";
my $login          =  "(?:(?:$user(?::$password)?\@)?$hostport)";
my $ip_schemepart  =  "(?://$login(?:/$urlpath)?)";

my $schemepart     =  "(?:$xchar*|$ip_schemepart)";
my $scheme         =  "(?:(?:$lowalpha|$digit|[+.-])+)";

# The generic form of a URL is:
my $genericurl     =  "(?:$scheme:$schemepart)";

# The predefined schemes:

# FTP (see also RFC959)
my $fsegment       =  "(?:(?:$uchar|[?:\@&=])*)";
my $ftptype        =  "(?:[AIDaid])";
my $fpath          =  "(?:$fsegment(?:/$fsegment)*)";
my $ftpurl         =  "(?:ftp://$login(?:/$fpath(?:;type=$ftptype)))";

# FILE
my $fileurl        =  "(?:file://(?:(?:$host)|localhost)?/$fpath)";

# HTTP
my $hsegment       =  "(?:(?:$uchar|[;:\@&=])*)";
my $search         =  "(?:(?:$uchar|[;:\@&=])*)";
my $hpath          =  "(?:$hsegment(?:/$hsegment)*)";
my $httpurl        =  "(?:http://$hostport(?:/$hpath(?:\\?$search)?)?)";

# GOPHER (see also RFC1436)
my $gopher_plus    =  "(?:$xchar*)";
my $selector       =  "(?:$xchar*)";
my $gtype          =  "(?:$xchar)";
my $gopherurl      =  "(?:gopher://$hostport(?:/$gtype(?:$selector" .
                      "(?:%09$search(?:%09$gopher_plus)?)?)?)?)";

# MAILTO (see also RFC822)
my $encoded822addr =  "(?:$xchar+)";
my $mailtourl      =  "(?:mailto:$encoded822addr)";

# NEWS (see also RFC1036)
my $article        =  "(?:(?:$uchar|[;/?:&=])+\@$host)";
my $group          =  "(?:$alpha(?:$alpha|$digit|[.+_-])*)";
my $grouppart      =  "(?:$article|$group|\\*)";
my $newsurl        =  "(?:news:$grouppart)";

# NNTP (see also RFC977)
my $nntpurl        =  "(?:nntp://$hostport/$group(?:/$digits)?)";

# TELNET
my $telneturl      =  "(?:telnet://$login(?:/)?)";

# WAIS (see also RFC1625)
my $wpath          =  "(?:$uchar*)";
my $wtype          =  "(?:$uchar*)";
my $database       =  "(?:$uchar*)";
my $waisdoc        =  "(?:wais://$hostport/$database/$wtype/$wpath)";
my $waisindex      =  "(?:wais://$hostport/$database\\?$search)";
my $waisdatabase   =  "(?:wais://$hostport/$database)";
my $waisurl        =  "(?:$waisdatabase|$waisindex|$waisdoc)";

# PROSPERO
my $fieldvalue     =  "(?:(?:$uchar|[?:\@&]))";
my $fieldname      =  "(?:(?:$uchar|[?:\@&]))";
my $fieldspec      =  "(?:;$fieldname=$fieldvalue)";
my $psegment       =  "(?:(?:$uchar|[?:\@&=]))";
my $ppath          =  "(?:$psegment(?:/$psegment)*)";
my $prosperourl    =  "(?:prospero://$hostport/$ppath(?:$fieldspec)*)";

# new schemes follow the general syntax
my $otherurl       =  $genericurl;

# Specific predefined schemes are defined here; new schemes
# may be registered with IANA
my $url            =  "$httpurl|$ftpurl|$newsurl|$nntpurl|$telneturl|" .
                      "$gopherurl|$waisurl|$mailtourl|$fileurl|" .
                      "$prosperourl|$otherurl";

# Add a few tests. (Not much, I might have missed some things...)

my @lines = (
    'http://www.ny.fnx.com/abigail/',
    'http://www.ny.fnx.com/abigail?foobar No more URL!',
    'ftp://foo.bar/foo/bar',
    'ftp://abigail:password@foo.bar/baz;type=ABCDEF',
    'foobar no URL!',
    'Bla; bla; <mailto:abigail@ny.fnx.com>',
    '<URL: news:wr3bucw59ig.fsf@kimbark.uchicago.edu>',
);


my $line;
foreach $line (@lines) {print "$&\n" if $line =~ m {$url};}

__END__

http://www.ny.fnx.com/abigail/
http://www.ny.fnx.com/abigail?foobar
ftp://foo.bar/foo/bar
ftp://abigail:password@foo.bar/baz;type=A
mailto:abigail@ny.fnx.com
news:wr3bucw59ig.fsf@kimbark.uchicago.edu

-- 
Party? Party, lord? Yes, lord. Right away, lord.
        - Beopunk Cyberwulf

Technical Details
Message-ID: <link-ya02408000R1501970249110001@news.uit.no>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
References: <59rvoh$i5d@epimetheus.algonet.se> <32dc574f.16481894@news.bctel.ca> <5b4r5h$r4c@fugue.clari.net> <5b76vc$4hb@bambam.soi.city.ac.uk> <5b7hl0$2of@fugue.clari.net> <rnewman-1101971004330001@mfd-dial6-4.cybercom.net> <vnd7mljsr84.fsf@k2.ccs.neu.edu> <slrn5dge57.2eg.cbbrowne@wolfe.brownes.org> <32D945A2.1D70@netscape.com>

Show Full Headers
Complete Article Headers
Message-ID: <link-ya02408000R1501970249110001@news.uit.no>
Subject: Re: heuristics for matching URLs in text/plain
Date: Wed, 15 Jan 1997 00:00:00 +0000
From: link@tss.no (Terje Bless)
References: <59rvoh$i5d@epimetheus.algonet.se> <32dc574f.16481894@news.bctel.ca> <5b4r5h$r4c@fugue.clari.net> <5b76vc$4hb@bambam.soi.city.ac.uk> <5b7hl0$2of@fugue.clari.net> <rnewman-1101971004330001@mfd-dial6-4.cybercom.net> <vnd7mljsr84.fsf@k2.ccs.neu.edu> <slrn5dge57.2eg.cbbrowne@wolfe.brownes.org> <32D945A2.1D70@netscape.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
X-Deja-AN: 209859885
Content-type: text/plain; charset=ISO-8859-1
Organization: TSS ltd.
Mime-version: 1.0
Newsgroups: news.software.readers