From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: RegExp: match everything except a certain string Date: Fri, 30 Nov 2007 11:26:32 -0500 Message-ID: References: <87fxz0j3wc.fsf@kamaloka.dhatu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1196440877 11546 80.91.229.12 (30 Nov 2007 16:41:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 30 Nov 2007 16:41:17 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 30 17:41:27 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Iy8ve-0000W9-3c for geh-help-gnu-emacs@m.gmane.org; Fri, 30 Nov 2007 17:41:26 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iy8vO-0005og-AB for geh-help-gnu-emacs@m.gmane.org; Fri, 30 Nov 2007 11:41:10 -0500 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.umontreal.ca!news.umontreal.ca.POSTED!not-for-mail Original-NNTP-Posting-Date: Fri, 30 Nov 2007 10:26:32 -0600 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) Cancel-Lock: sha1:cAAIzP7p2yUQggKmt/OcuIlDg4s= Original-Lines: 46 X-Usenet-Provider: http://www.giganews.com Original-NNTP-Posting-Host: 132.204.27.213 Original-X-Trace: sv3-nIqnGrFtFnEuVp5eyc6mNbJw5h9bjQqLrSmhgWqo3aXkWvNVDdGCOML4Gra7ataw7JgA6MYrfr7WCBy!JXJh8j0yx5UqvPZlxQXXMjaKuFvxXUPnaTpduj99utrgzd8b4hlDtqOGNBmdhcGUnLMtWbW+95Ln!HGcNJFlzHX/OtWZX4Q== Original-X-Complaints-To: abuse@umontreal.ca X-DMCA-Complaints-To: abuse@umontreal.ca X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.36 Original-Xref: shelby.stanford.edu gnu.emacs.help:154302 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:49730 Archived-At: > [^s]?[^u]?[^b]?[^t]?[^i]?[^t]?[^l]?[^e] = {},?$ Nice try, but no cigar ;-) How 'bout something like: "\\(?:[^s]\\|s\\(?:[^u]\\|u\\(?:[^b]\\|b\\(?:[^t]\\|t\\(?:[^i]\\|i\\(?:[^t]\\|t\\(?:[^l]\\|l\\(?:[^e]\\|e[^\t\n ]\\)\\)\\)\\)\\)\\)\\)\\)" this is just a starting point, because even if you have "subtitle" in your buffer the "title" part doesn't match "subtitle", so a regexp-search may find "title" as a match: negation in regexp search is pretty tricky. Stefan (defun regexp-not-in (words endchars &optional prefix) "Return a regexp that matches anything other than words in WORDS. ENDCHARS is a list containing the chars that can appear after a word." ;; `prefix' is only used internally. (if prefix (setq words (all-completions prefix words)) (setq prefix "")) (let* ((pos (length prefix)) (empty (when (member prefix words) (setq words (remove prefix words)) t)) (chars (delete-dups (mapcar (lambda (word) (aref word pos)) words))) (chars-re (regexp-opt-charset (if empty (nconc chars endchars) chars))) (nonchars-re (concat "[^" (substring chars-re 1 -1) "]"))) (cond ((and empty (null endchars)) ;; If there are no termination chars, then we have to simply disallow ;; this match altogether. "\\`") ((null chars) nonchars-re) (t (concat "\\(?:" nonchars-re "\\|" (mapconcat (lambda (char) (setq char (string char)) (concat char (regexp-not-in words endchars (concat prefix char)))) chars "\\|") "\\)")))))