|
From: | Greg Hill |
Subject: | Re: Problem with re-search-backward and "\\=" |
Date: | Tue, 16 Sep 2003 11:57:03 -0700 |
GNU Emacs 21.1 Suppose I have this in a buffer: foo bar If point is immediately after foo, then (re-search-forward "\\= *") leaves point immediately before bar, as one would expect. However, with point immediately before bar (re-search-backward " *\\=") fails. I would have expected this search to have succeeded, leaving point just after foo. The definition of `\=' in the elisp info page "Regexp Backslash" is:matches the empty string, but only at point. (This construct is not defined when matching against a string.)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.
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-beninning 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 hope this helps. --Greg
[Prev in Thread] | Current Thread | [Next in Thread] |