<<< Date Index >>>     <<< Thread Index >>>

Re: colours and quotes and regex libs? (was: Re: colours and quotes)



On Fri, May 28, 2004 at 09:04:00PM +0200, Nicolas Rachinsky wrote:
> * David Yitzchak Cohen <lists+mutt_users@xxxxxxxxxxxxxx> [2004-05-28 14:29 
> -0400]:
> > Can you try something like this just to be sure?  (The regex was imported
> > from Perl, so feel free to change whatever's necessary to fix it.)
> > 
> > color body red default 
> > '((http|https|ftp|gopher|finger):\/\/(.+?))(?="|\s|&gt;|\))'
> 
> Hmm, my mutt doesn't accept +? and (?=. But my (not very good) url
> regexp works fine for (many) URLs which are only a part of a line.
> color body brightblue   default "((ftp|https?)://|(ftp|www[-a-z0-9]*)\\.)[^ 
> \t\r\n\"<>]*[^].,:;!)? \t\r\n<>\"]"
> 
> I'm too lazy to think about how to convert your regexp to something my
> mutt accepts, and I'm too lazy to find (or produce) a test case.

Unfortunately, there's not a completely effective replacement for (?=),
because you want to match the character(s) that follow the URL, but you
don't want to color them.

Here's a mutt-friendly regex, based on David's Perl regex, that seems to do
well:

color body brightblue default \
  '(https?|ftp|gopher|finger):\/\/([^"'"'"' \t\n)>.,!?&]|[.,!?][^"'"'"' 
\t\n)>.,!?&]|&([^g]|$)|&g([^t]|$)|&gt([^;]|$))+'

(Watch out for line-wrapping.  There's a space character before each \t.)

The URL can't contain ["' \t\n)>].
The URL can contain [.,!?], but only when not followed by ["' \t\n)>.,!?&].
The URL can contain &, but only when not followed by gt;.

Ronald

P.S.  Here are some examples that the regex colors properly.

http://www.example.com
<http://www.example.com>
"http://www.example.com";
'http://www.example.com'
http://www.example.com/?f=1&g=2
http://www.example.com/?foo&;
http://www.example.com/?f&g
&lt;http://www.example.com/?foo&bar&gt;
Have you seen http://www.example.com?  It's great!
Go to http://www.example.com...
Try http://www.example.com, I think you'll like it.
He said, "Check out http://www.example.com.";

Send me examples that it colors incorrectly and I'll try to refine it.