[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Word Boundary problem with regex
From: |
Tim X |
Subject: |
Re: Word Boundary problem with regex |
Date: |
06 Jun 2005 18:37:28 +1000 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
Tim Johnson <tim@johnsons-web.com> writes:
> In case of word wrapping the text between (but not including) the lines
> of asterisks should be on one line:
>
> I am using the following expression
> *******************************************************************************
> \\([^][ \t\r\n{}()]+\\):[
> ]*\\(d\\(ef\\|oes\\)\\|func\\(tion\\)\\|has\\|sub?\\)
> *******************************************************************************
>
> To colorize the following words: "def" "does" "func" "function" "has"
> "sub" - which define subroutines.
>
> When I type the following: test: def[val][print val], "def" is
> colorized properly. One would exect that adding a letter to "def" would
> turn off the target color, but does not. This suggests to me that
> I have not properly defined the word boundary in the expression above.
>
> Can anyone tell me what I am doing wrong?
>
> FYI: This is for the rebol programming language (www.rebol.com), it
> should be noted that in lispish fashion, a subroutine is an
> expression, not an immutable control structure.
>
> thanks
> tim
>
> --
> Tim Johnson <tim@johnsons-web.com>
> http://www.alaska-internet-solutions.com
I'm not entirely clear on exactly what it is your trying to match, but
would recommend having a look at regexp-opt as it is particularly
useful for defining regexp for font-locking. A reasonably clear
example of its use can be found in sql.el - the sql-mode which comes
bundled with emacs.
HTH
Tim
,----[ C-h f regexp-opt RET ]
| regexp-opt is a compiled Lisp function in `regexp-opt'.
| (regexp-opt STRINGS &optional PAREN)
|
| Return a regexp to match a string in STRINGS.
| Each string should be unique in STRINGS and should not contain any regexps,
| quoted or not. If optional PAREN is non-nil, ensure that the returned regexp
| is enclosed by at least one regexp grouping construct.
| The returned regexp is typically more efficient than the equivalent regexp:
|
| (let ((open (if PAREN "\\(" "")) (close (if PAREN "\\)" "")))
| (concat open (mapconcat 'regexp-quote STRINGS "\\|") close))
|
| If PAREN is `words', then the resulting regexp is additionally surrounded
| by \< and \>.
`----
--
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you
really need to send mail, you should be able to work it out!