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: Thorsten Jolitz
Subject: Re: regexp question: match anything but not a group?
Date: Thu, 03 Apr 2014 21:48:01 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

> Thorsten Jolitz <tjolitz@gmail.com> writes:
>
>> 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?
>
> (defun pjb-rx-not-string (string)
>   (case  (length string)
>     ((0)        `(* anything))
>     ((1)        `(not (any ,string)))
>     (otherwise  `(or (not (any ,(subseq string 0 1)))
>                      (seq ,(subseq string 0 1)
>                           ,(pjb-rx-not-string (subseq string 1)))))))
>
>
> (defun pjb-regexp-not-string (string)
>   (let ((all (coerce (delete-duplicates
>                       (sort (coerce string 'list) (function <))) 'string)))
>     (rx-to-string `(seq bot
>                         (* (not (any ,string)))
>                         ,(pjb-rx-not-string string)
>                         (* (not (any ,string)))
>                         eot))))
>
> (pjb-regexp-not-string "\\)")
> --> "\\(?:\\`[^)\\]*\\(?:[^\\]\\|\\\\[^)]\\)[^)\\]*\\'\\)"

Wow, impressive, thank you. 

At first sight reads like pseudo-code to me, probably more CL-style than
elisp style. 

any, anything, otherwise ... unusual stuff, I don't even find those
functions with C-h f (not even after loading cl.el and cl-extra.el). 

This is definitely hard to digest ...

-- 
cheers,
Thorsten




reply via email to

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