🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #29265

heuristics for matching URLs in text/plain (was Re: Netscape 4 hitting the streets)

#29265
From: Jamie Zawinski
Date: Sun, 12 Jan 1997 00:00
65 lines
3065 bytes
Christopher B. Browne wrote:
> 
> The *terminator* of the regex should be one of the following:
>   a: White space
>   b: ">"
>   c: A doublequote" - e.g. `"'
>   d: A single quote:  "'"
>   e: A period.
> 
> Ideally, one should take the data including terminator, and strip off the
> terminator.

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.

 = First pass at matching a URL: (whitespace added for readability)

   \b
   \(about\|ftp\|file\|gopher\|http\|https\|mailto\|mailbox\|
     rlogin\|news\|snews\|telnet\|tn3270\|wais\):
   [^ \t<>`()[]{}!'\",]+

   but if the matched string contains "?" or begins with "mailto",
   then instead of 

      [^ \t<>`()[]{}!'\",]+

   we use

      [^ \t<>`()[]{}!'\"]+

   that is, commas are considered to be a part of the URL if it's
   a mailto, or a CGI or imagemap (like "foo.html?300,400".)

   (One could probably code a single regexp that said that...)

 = Next, we strip off unlikely characters from the end of the URL:
   "[.,!;-?#]+$"

   (This could also probably be included in the original regexp,
   if the matcher isn't a "hungry" one...)

 = If the resultant URL has length < 7, give up.

 = If the resultant URL ends in ":", give up.

> Apparently there's an RFC that indicates that the "correct" way of
> describing a URL in news looks like <http://www.ccs.neu.edu>, which is
> nicely unambiguous to match using a regex.

Unfortunately, educating users to do that is an impossible task; users
think that they're typing human-readable text, not machine-readable
text.

-- 
Jamie Zawinski    jwz@netscape.com   http://www.netscape.com/people/jwz/
``The hateful :-) means `just kidding' and is used by people who would
  dot their i's with little circles and should have their eyes dotted
  with Drano.''   -- Penn Jillette

Technical Details
Message-ID: <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
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>

Show Full Headers
Complete Article Headers
Message-ID: <32D945A2.1D70@netscape.com>
Subject: heuristics for matching URLs in text/plain (was Re: Netscape 4 hitting the streets)
Date: Sun, 12 Jan 1997 00:00:00 +0000
From: Jamie Zawinski <jwz@netscape.com>
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>
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: 209402582
Content-type: text/plain; charset=us-ascii
Organization: Netscape Communications Corporation, Mozilla Division
Mime-version: 1.0
Newsgroups: news.software.readers
X-mailer: Mozilla 3.0 (X11; U; IRIX 6.2 IP22)