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: Problem with re-search-backward and "\\=" Date: Wed, 17 Sep 2003 08:13:55 +0000 Organization: muc.de e.V. -- private internet access Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <3459kb.h6.ln@acm.acm> References: NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1063807578 9272 80.91.224.253 (17 Sep 2003 14:06:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 17 Sep 2003 14:06:18 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 17 16:06:17 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19zcwi-0003fw-00 for ; Wed, 17 Sep 2003 16:06:17 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 19zcsB-0007uo-1v for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Sep 2003 10:01:35 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed.news.nacamar.de!news.space.net!news.muc.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 61 Original-NNTP-Posting-Host: acm.muc.de Original-X-Trace: marvin.muc.de 1063806032 44962 193.149.49.134 (17 Sep 2003 13:40:32 GMT) Original-X-Complaints-To: news-admin@muc.de Original-NNTP-Posting-Date: 17 Sep 2003 13:40:32 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:116666 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 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 Xref: main.gmane.org gmane.emacs.help:12587 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:12587 Greg Hill wrote on Tue, 16 Sep 2003 11:57:03 -0700: >>GNU Emacs 21.1 >>Suppose I have this in a buffer: >>foo bar >>With point immediately before bar (re-search-backward " *\\=") fails. >>I would have expected this search to have succeeded, leaving point just >>after foo. >>Is this a bug, or have I misunderstood something? > Alan, > You have misunderstood the nature of the "greediness" of the '*' -- > and probably also the '+' -- postfix operator when applied to > backward searches. It is not "symmetrical" with its effect on > forward searches. I suggest you do some experimentation with these > operators, never minding the "\\=" for the moment, to better > understand the way these postfix operators work. OK, I think I've got it now. It finds the _minimum_ match it can. With my expression, it matches on zero spaces. It's even documented in the elisp info pages: "A true mirror-image of `re-search-forward' would require a special feature for matching regular expressions from end to beginning. It's not worth the trouble of implementing that." ;-( > I may not have this completely right, but this is the way I > conceptualize it. When searching forward, the match-beginning > advances forward from point until the first possible match is found; > then match-beginning is fixed and match-end advances until going any > farther would break the rule or exceed the specified limit. In > searching backward, the match-beginning moves backward until the > first possible match is found; then match-beginning is fixed and the > match-end advances forward until going any farther would break the > rule, using the initial value of point as the limit to how far the > match-end is allowed to advance. > I have never experimented with the "non-greedy" postfix operators > '*?' '+?' and '??', so I can't tell you how using them effects the > conceptualization described above. I wasn't aware these existed. Thanks for the tip! > I hope this helps. Very much so. For what I actually need to do (moving back any combination of whitespace and a few things like "//." as the first non-space stuff on a line), I can do it easily enough by hand. Many thanks. > --Greg -- 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").