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

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

Re: regexp question: match anything but not a group?


From: Andreas Röhler
Subject: Re: regexp question: match anything but not a group?
Date: Wed, 02 Apr 2014 10:07:20 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Am 01.04.2014 23:30, schrieb Thorsten Jolitz:

Hi List,

how can I write a regexp that acts like e.g.

,------
| ".*?"
`------

but does not match a group like e.g.

,---------------------
| (regexp-quote "\\)")
`---------------------

?

This works more or less but does not seem to be very robust

,---------
| "[^)]*?"
`---------

since ')' could appear in other contexts than the group. How can I
negate a specific group of characters and not only any occurence of
single characters?



You need look-ahead-assertions, which aren't implemented in Emacs AFAIK.
Here is a workaround to play with:

(progn
  (and (looking-at ".*")
       (not (eq (char-after) ?\))))
  (message "%s" (match-string-no-properties 0)))

Test with more than one char ahead writing n char-after:

(not (eq (char-after (+ 1 (point)) MY-CHAR)))
(not (eq (char-after (+ 2 (point)) MY-CHAR)))





reply via email to

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