From: gnuist
Subject: On refining regexp by adding exceptions systematically
Date: 
Message-ID: <9e8ebeb2.0210030427.4544cb00@posting.google.com>
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.

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. 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.

Thanks a lot!
gnuist007

From: Kaz Kylheku
Subject: Re: On refining regexp by adding exceptions systematically
Date: 
Message-ID: <cf333042.0210031038.56c8ee4e@posting.google.com>
·········@hotmail.com (gnuist) wrote in message news:<····························@posting.google.com>...
> Here is regular expression in emacs lisp that initially seems to work
> for the job:

Goddamned idiot, you have already been advised not to crosspost Lisp
questions to comp.lang.lisp. If you can't understand a simple thing
like that, you aren't fit to participate in any activity that requires
thought.
From: Kaz Kylheku
Subject: Re: On refining regexp by adding exceptions systematically
Date: 
Message-ID: <cf333042.0210031504.5409ce3b@posting.google.com>
···@ashi.footprints.net (Kaz Kylheku) wrote in message news:<····························@posting.google.com>...
> ·········@hotmail.com (gnuist) wrote in message news:<····························@posting.google.com>...
> > Here is regular expression in emacs lisp that initially seems to work
> > for the job:
> 
> Goddamned idiot, you have already been advised not to crosspost Lisp
                                                                  ^Emacs

> questions to comp.lang.lisp. 

:)
From: Alan Mackenzie
Subject: Re: On refining regexp by adding exceptions systematically
Date: 
Message-ID: <cjpmna.p51.ln@acm.acm>
gnuist <·········@hotmail.com> 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: ····@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").
From: Christopher Browne
Subject: Re: On refining regexp by adding exceptions systematically
Date: 
Message-ID: <annfi3$g220e$3@ID-125932.news.dfncis.de>
Oops! ·········@hotmail.com (gnuist) was seen spray-painting on a wall:
> 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.

> 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. 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.

If your specification sucks, "adding exceptions" is just going to make
the code "suck worse" as you find more of them.

Maybe you need to do the design work up front to determine the /real/
specification for whatever it was that you were searching for.

And perhaps you should set up followup to your /favorite/ newsgroup?
This isn't really a Unix question, nor is it a Lisp question, so
discussion probably shouldn't continue in these newsgroups.
-- 
(reverse (concatenate 'string ·············@" "sirhc"))
http://cbbrowne.com/info/emacs.html
"Necessity is the mother of invention" is a silly proverb.  "Necessity
is the  mother of  futile dodges"  is much closer  to the  truth.  The
basis of growth of modern  invention is science, and science is almost
wholly the outgrowth of pleasurable intellectual curiosity.
-- Alfred N. Whitehead
From: gnuist
Subject: Re: On refining regexp by adding exceptions systematically
Date: 
Message-ID: <9e8ebeb2.0210070732.6a539ccc@posting.google.com>
> > 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.

> 
> If your specification sucks, "adding exceptions" is just going to make
> the code "suck worse" as you find more of them.
> 
> Maybe you need to do the design work up front to determine the /real/
> specification for whatever it was that you were searching for.

I am following the build-fix paradigm rather than the OOP design one.
Perhaps give me some solution in emacs-lisp.