Noam Postavsky <[email protected]>
writes:

> On Fri, Aug 22, 2014 at 12:21 PM, Thorsten Jolitz
> <[email protected]> wrote:
>> foo.el and other libraries of mine contains regexps with a technique I
>> stole from the Org developers: match every possible char with
>>
>> ,----
>> | "[^^@]+"
>> `----
>>
>> with ^@ being the NULL character entered with C-q.
>
> By the way, you should be able to use lisp string escape syntax
> instead of a literal NUL: "[^\0]+".

in org-mode they write it like "[^\000]+", and it should work really,
but I tried it and it failed sometimes, while the literal NUL was 100pc
reliable. I will try it again.

> Also, wouldn't this fail to match NUL chars? (rx (1+ anything)) gives
> "\\(?:.\\|\n\\)+", seems like that would be better...

isn't the whole idea based on the fact that NUL chars should not appear
ever in non-binary files (ok, I just proved the contrary with my regexps
...)?


This looks like a nice alternative, however I'm struggling a bit to make
it a regexp subgroup

#+BEGIN_SRC emacs-lisp
(string-match "\\(\\(.\\|\n\\)+?\\)\\(world\\)" "hello \nworld")
(match-string 0 "hello \nworld")
#+END_SRC

#+results:
: hello 
: world


#+BEGIN_SRC emacs-lisp
(string-match "\\(\\(.\\|\n\\)+?\\)\\(world\\)" "hello \nworld")
(match-string 1 "hello \nworld")
#+END_SRC

#+results:
: hello 

#+BEGIN_SRC emacs-lisp
(string-match "\\(\\(.\\|\n\\)+?\\)\\(world\\)" "hello \nworld")
(match-string 2 "hello \nworld")
#+END_SRC

#+BEGIN_SRC emacs-lisp
(string-match "\\(\\(:?.\\|\n\\)+?\\)\\(world\\)" "hello \nworld")
(match-string 2 "hello \nworld")
#+END_SRC

#+results:
: 

#+BEGIN_SRC emacs-lisp
(string-match "\\(\\(.\\|\n\\)+?\\)\\(world\\)" "hello \nworld")
(match-string 3 "hello \nworld")
#+END_SRC

#+results:
: world

-- 
cheers,
Thorsten

-- 
You received this message because you are subscribed to the Google Groups 
"magit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to