Regex Troubles

1999-08-19 Thread Nathan Cullen

I have the following line w/regex in my .muttrc to highlight URLs in my
messages:

color body yellow default (http|ftp)://[_a-zA-Z0-9\./~\-]+

However, when I get a url with a question mark in it, it does not work
properly.  I thought that the simple solution would be to add a \? to the
character class, producing the following regex:

color body yellow default (http|ftp)://[_a-zA-Z0-9\./~\-\?]+

This does not work.  When I run mutt with this in my .muttrc, mutt reports
the following: 

Error in /home/heat/.muttrc, line 67: Invalid range end
source: errors in /home/heat/.muttrc

Line 67, of course, refers to the line described above.  Am I missing
something obvious?  I don't quite understand what "Invalid range end" means.

Thanks for any assitance you folks can give...

-- 
===
 Nathan Cullen  [EMAIL PROTECTED]
===



Re: Regex Troubles

1999-08-19 Thread David DeSimone

Nathan Cullen [EMAIL PROTECTED] wrote:

 color body yellow default (http|ftp)://[_a-zA-Z0-9\./~\-]+
 
 color body yellow default (http|ftp)://[_a-zA-Z0-9\./~\-\?]+
 
 Error in /home/heat/.muttrc, line 67: Invalid range end

Mutt has its own internal parser that examines your input lines before
the regexp parser gets a look at them.  Mutt's parser uses backslashes
as the quote character, so your first regexp looks like this, once it's
been stored internally in Mutt:

(http|ftp)://[_a-zA-Z0-9./~-]+

In other words, your attempt to quote the "." and "-" characters has
failed, because Mutt saw the backslash first, and processed it, before
the text was even processed as a regular expression.  However, the above
works, because I think "." is not a special character when inside a
character class, and furthermore, "-" is not a special character when
found as the very first or very last character in a class.  So you got
lucky, and it worked anyway.  :)

Your second regexp comes out look like this:

(http|ftp)://[_a-zA-Z0-9./~-?]+

Again, the backslashes are removed, but most of them are superfluous,
because "." and "?" are not treated as special within a character class,
so they work correctly.  However, your "-" character is no longer the
last one in the character class, so it is being treated as a range
operator, and the range is invalid because "~" thru "?" is an invalid
ASCII range (the code for "~" is greater than the code for "?").

To fix this, I suggest that you remove the backslashes, since they
aren't working, and aren't needed, so it's best not to pretend that they
are doing something for you, and furthermore that you move the "?"
character before the "-" at the end of the class.  That should make the
expression do what you want.

As a further suggestion, consider removing the "A-Z" portion of your
regexp, since Mutt matches regexp's in case-insensitive form, as long as
all the characters are lower-case in your regexp, so your specification
of A-Z is redundant.

If you really do want the backslashes to appear in your regexp (at some
future time, perhaps), you must either double them up, "\\", or else
enclose the entire regexp is 'single-quotes', so that Mutt does not
parse or remove the backslashes from the string.

Hope this helps,
-- 
David DeSimone   | "The doctrine of human equality reposes on this:
[EMAIL PROTECTED]   |  that there is no man really clever who has not
Hewlett-Packard  |  found that he is stupid." -- Gilbert K. Chesterson
Convex Division  |PGP: 5B 47 34 9F 3B 9A B0 0D  AB A6 15 F1 BB BE 8C 44