help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: regexp problem


From: Pascal Bourguignon
Subject: Re: regexp problem
Date: Sat, 12 Aug 2006 12:12:26 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

"Þorne" <ego111@gmail.com> writes:

> Pascal Bourguignon wrote:
>> You can match groups:
>>
>> a\(b\)c
>>
>> so the match number 0 is the whole regexp: abc
>> but the match number 1 is only b
>
> Sorry to be dense, but do you mean something like this:
>
> (search-forward-regexp "a\\(b\\)c\\0")


(when (search-forward-regexp "a\\(b\\)c")
  (let ((all    (match-string 0))
        (only-b (match-string 1)))
    (goto-char (match-end 0))
    (insert (format "\nall = %s\nonly-b = %s\n" all only-b))))



> because i can't get anything like it to work.  I don't really follow
> the documentation for the \<digit> construct in regexps at all...
>
> In fact the code above finds a string that looks like `abc0' instead of
> just `b'.
>
> Specifically i am trying to make a regexp for define-generic-mode to
> colorize the string`*' but only if it is in a string that looks like
> `(*)'.  But not colorize the surrounding parens.

Read with utmost attention the help about the variable font-lock-keywords.

 (MATCHER . SUBEXP)

 ("fu\\(bar\\)" . 1)    substring "bar" within all occurrences of "fubar" in
                        the value of `font-lock-keyword-face'.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

COMPONENT EQUIVALENCY NOTICE: The subatomic particles (electrons,
protons, etc.) comprising this product are exactly the same in every
measurable respect as those used in the products of other
manufacturers, and no claim to the contrary may legitimately be
expressed or implied.


reply via email to

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