[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: regular expression help (again)
From: |
Barry Margolin |
Subject: |
Re: regular expression help (again) |
Date: |
Thu, 24 Jan 2013 04:01:34 -0500 |
User-agent: |
MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
In article <mailman.18180.1359012159.855.help-gnu-emacs@gnu.org>,
Luca Ferrari <fluca1978@infinito.it> wrote:
> Hi,
> there is something I'm missing: I'm still writing my mode for a
> programming language and I'd like to set a font-lock for a block of
> lines that begins with /SOMETHING and ends with /* like the following:
>
> /MASK
> Field 1: _____
> Field 2: _____
> /*
>
> So I defined the following regular expression to first match the whole block:
>
> "^/\w+[ \t\n]+(.*\n)/\*$"
>
> but it is not working, in particular testing it against
> re-search-forward the \w+ works as expected but the [ \t\n]+
> subsedquent part is blocking the regular expression. What am I doing
> wrong?
>
> Second question, within the same block would it be possible to set a
> fot-lock for any word that is not made by underscores and to set
> another font-lock for any _ found in the block? I need a little
> suggestion about this (if possible).
In Lisp code you need to double the backslashes that are used for regexp
escape sequences, since backslash is also the string escape character.
So change it to:
"^/\\w+[ \t\n]+(.*\n)/\\*$"
When you're typing a regexp interatively in response to a command
prompt, you don't need to do this. However, \t and \n don't have any
special meaning in regexp syntax (they're part of string syntax), so you
have to enter them literally with C-q TAB anc C-q C-j.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***