From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.help Subject: Re: On refining regexp by adding exceptions systematically Date: Sat, 5 Oct 2002 13:31:24 +0000 Organization: muc.de e.V. -- private internet access Sender: help-gnu-emacs-admin@gnu.org Message-ID: References: <9e8ebeb2.0210030427.4544cb00@posting.google.com> NNTP-Posting-Host: localhost.gmane.org X-Trace: main.gmane.org 1033825626 11188 127.0.0.1 (5 Oct 2002 13:47:06 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 5 Oct 2002 13:47:06 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17xpGq-0002uK-00 for ; Sat, 05 Oct 2002 15:47:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17xpG3-0002ED-00; Sat, 05 Oct 2002 09:46:15 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!uni-erlangen.de!lmu.de!news.muc.de!not-for-mail Original-Newsgroups: gnu.emacs.help,gnu.utils.help,comp.lang.lisp,comp.unix.shell,comp.unix.programmer Original-Followup-To: gnu.emacs.help Original-Lines: 52 Original-NNTP-Posting-Host: acm.muc.de Original-X-Trace: marvin.muc.de 1033824790 37099 193.149.49.134 (5 Oct 2002 13:33:10 GMT) Original-X-Complaints-To: news-admin@muc.de Original-NNTP-Posting-Date: 5 Oct 2002 13:33:10 GMT User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686)) Original-Xref: shelby.stanford.edu gnu.emacs.help:105747 gnu.utils.help:4082 comp.lang.lisp:95638 comp.unix.shell:134034 comp.unix.programmer:143847 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:2293 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:2293 gnuist wrote on 3 Oct 2002 05:27:55 -0700: > Here is regular expression in emacs lisp that initially seems to work > for the job: > [A-Z][A-Z][A-Z][0-9]+ > After running it on a number of uses, I find that there is an exception > to it, namely PJP89898. Rather than rehashing the code after having > forgotten it and reworking my regexp expression (every time I find an > exception) in some convoluted way, is there a systematic way to add an > exception or a series of exceptions to the regexp? I am sure that there > are a number of ways to do this and each has its merits. Regular expressions are designed to find string expressions which are, well, regular. If you really want to add in an exception like you've got, you're going to end up with something horrible. It can be done, but like rowing the Atlantic, why bother? > I am using this regexp in two ways in a different program. In the > first one (looking-at regexp) so that it assumes that cursor is on it. (and (looking-at regexp) (not (looking-at "PJP89898"))) > In the second one (search-forward-regexp regexp) in a narrowed region > so that one is trying to find if there is one. It seems to me that it > is a little tricky to do this. Perhaps an example code would help with > exception implemented for searching on a line. (let (found (startpos (point))) (while (and (setq found (search-forward-regexp regexp nil t)) (save-excursion (goto-char (match-data 0)) (looking-at "PJP89898")))) (if found (point) (goto-char startpos) nil)) I haven't tested either snippet. Hope this helps. By the way, it would be helpful if you could set a Followup-To: header, so that people know what your "home" group is. It also makes you look less like a troll. > Thanks a lot! > gnuist007 -- Alan Mackenzie (Munich, Germany) Email: aacm@muuc.dee; to decode, wherever there is a repeated letter (like "aa"), remove half of them (leaving, say, "a").