From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thorsten Jolitz Newsgroups: gmane.emacs.help Subject: Re: regexp question: match anything but not a group? Date: Thu, 03 Apr 2014 21:48:01 +0200 Message-ID: <87zjk2gpou.fsf@gmail.com> References: <87zjk4louc.fsf@gmail.com> <87txacab0b.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1396554450 20919 80.91.229.3 (3 Apr 2014 19:47:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 3 Apr 2014 19:47:30 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 03 21:47:23 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WVnbf-0003c5-HE for geh-help-gnu-emacs@m.gmane.org; Thu, 03 Apr 2014 21:47:23 +0200 Original-Received: from localhost ([::1]:46013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVnbf-0001ND-6D for geh-help-gnu-emacs@m.gmane.org; Thu, 03 Apr 2014 15:47:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42535) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVnbG-0001CN-JO for help-gnu-emacs@gnu.org; Thu, 03 Apr 2014 15:47:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WVnbA-0000RE-M6 for help-gnu-emacs@gnu.org; Thu, 03 Apr 2014 15:46:58 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:34476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVnbA-0000R7-FD for help-gnu-emacs@gnu.org; Thu, 03 Apr 2014 15:46:52 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WVnb9-0003AU-9U for help-gnu-emacs@gnu.org; Thu, 03 Apr 2014 21:46:51 +0200 Original-Received: from g231227208.adsl.alicedsl.de ([92.231.227.208]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 03 Apr 2014 21:46:51 +0200 Original-Received: from tjolitz by g231227208.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 03 Apr 2014 21:46:51 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 64 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: g231227208.adsl.alicedsl.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:iY4+pcNRP4CzCnDjuHcYioqH9KY= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:96953 Archived-At: "Pascal J. Bourguignon" writes: > Thorsten Jolitz 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