[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: regexp match failure

From: Kevin Rodgers
Subject: Re: regexp match failure
Date: Wed, 22 Nov 2006 09:59:25 -0700
User-agent: Thunderbird (Windows/20061025)

sandro.dentella wrote:
>   I can't understand wht's wrong with the following regexp:
> (define-derived-mode mutt-mode text-mode "Mutt"
>   (make-face 'mutt-variable-face)
>   (font-lock-add-keywords
>    nil
>    '(
>     ("^\\(Date\\|Status:\\)" 1 font-lock-keyword-face)

Don't you mean "^\\(Date\\|Status\\):", with either SUBEXP = 1 as-is to
leave the colon unfontified or 0 to fontify it?

>     ("^\\(\\S+:\\)" 1 font-lock-keyword-face)
>   ))
>   (font-lock-mode 1)
> )
> The first ine works, it colors Date: and Status:, the second line
> should in my opinion be just a generalized version of the first line
> but it does not work.

`\S' is not a valid regexp, it needs a following syntax code.  And since
you apparently want to match characters which *are* letters rather than
those which are *not*, `\s' is the appropriate construct with the `w'
code: "^\\sw+:"

Again, don't be afraid to use 0 as the font-lock-keywords SUBEXP and
avoid `\(...\)' groupings when they're not necessary.

> BTW, i'd have written:
>   "^[-\\S]+:"
> but it doens't work eather. Can anybody explain me what I'm missing?

Inside of the `[...]' construct, backslash constructs are not special
(RTFM).  But in Emacs 22 you can do this: "^[[:alnum:]]+:"


reply via email to

[Prev in Thread] Current Thread [Next in Thread]