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

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

Re: Is it valid to use the zero-byte "^@" in regexps?


From: Nicolas Richard
Subject: Re: Is it valid to use the zero-byte "^@" in regexps?
Date: Wed, 18 Jun 2014 11:52:11 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.91 (gnu/linux)

Thorsten Jolitz <tjolitz@gmail.com> writes:
> To rule out a fundamental problem - is it valid to have the zero-byte
> (inserted with C-q C-@) appear in a regexp like this? 
>
> ,--------------------------------------------------------
> | "^#\\+begin_src[[:space:]]+emacs-lisp[^^@]*\n#\\+end_src"
> `--------------------------------------------------------

I don't see why it wouldn't be valid, but I don't know. If it is
desirable is another question : it would be better to search for the
beginning, then search for the end with another regexp.

> If so, this regexp should reliably match any 
>
> ,-----------------------
> | #+begin_src emacs-lisp
> |  [...]
> | #+end_src
> `-----------------------

>From the first occurrence of
#+begin_src emacs-lisp
;; after point to the last occurence of
#+end_src
in the buffer. If there's more than one, they'll be part of the match
too. e.g. if there's another block in the same document :
#+begin_src sh
echo whatever.
#+end_src
it'll be part of the match too. If you don't want that, make the star
non-greedy by appending a question mark to it:
(re-search-forward "^#\\+begin_src[[:space:]]+emacs-lisp[^^@]*?\n#\\+end_src")

> no matter whats inside the block, right?

Except NUL characters of course.

-- 
Nico.



reply via email to

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