----- Forwarded message from Stefan Monnier <monnier+gnu/emacs(a)tequila.cs.yale.edu>
-----
X-Mailer: exmh version 2.1.0 04/14/1999
From: "Stefan Monnier" <monnier+gnu/emacs(a)tequila.cs.yale.edu>
To: Jan Vroonhof <vroonhof(a)math.ethz.ch>
Subject: Re: non-greedy regexps
Date: Fri, 03 Dec 1999 01:01:10 -0500
"Stefan Monnier <foo(a)acm.com>"
<monnier+gnu/emacs/sources/news/(a)tequila.cs.yale.edu> writes:
> As noted in gnu.emacs.help I'd like to have non-greedy regexp operators,
> as Perl provides, for example. The idea is that `*?' is like `*' but
> will match as little as possible. The same thing applies to `??' and `+?'.
> The patch below implements this.
If I recall correctly there already was a patch that implemented this
(but only the *? and +? operators).
In addition it implemented shy groups, using the (:? syntax.
This patch was submitted for both XEmacsen but only went into XEmacs
(as of 20.4).
The XEmacs version of regexp-opt also uses shy groups.
I tried to code up shy-groups and arrived at something that seems to work,
but I had some doubts because of some suspicious comments in regex.c.
Luckily those comments provide sample tricky regexps and sure enough
I fail on them. Funnily enough, XEmacs fails on them as well:
emacs/src-0% /softs/xemacs-21.1.2/bin/xemacs --batch --eval "(message
\"%s\" (list (string-match
\"^\\\\(?:\\\\(a*\\\\)*\\\\(b*\\\\)*\\\\)*\$\" \"aba\") (match-string
1 \"aba\")))"
(nil nil)
emacs/src-0% /softs/xemacs-21.1.2/bin/xemacs --batch --eval "(message
\"%s\" (list (string-match
\"^\\\\(\\\\(a*\\\\)*\\\\(b*\\\\)*\\\\)*\$\" \"aba\") (match-string 1
\"aba\")))"
(0 a)
emacs/src-0%
Maybe this was fixed since 21.1.2, of course.
I haven't looked at XEmacs code, but I assume it does something very similar
to mine and the problem doesn't seem easy to solve. Maybe it can be solved
without too much hacking, but it requires a much better understanding of
the code than I have.
Stefan
----- End forwarded message -----
--
Jan Vroonhof
http://www.math.ethz.ch/~vroonhof/
Mathematik, vroonhof @ math.ethz.ch
HG E16, ETH-Zentrum, Tel: +41-1-6325456/25154
Raemistrasse 101, CH-8092 Zuerich. Fax: +41-1-6321085