[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] searching for regexes containing ^ or $

From: Benno Schulenberg
Subject: [Nano-devel] searching for regexes containing ^ or $
Date: Tue, 21 Apr 2015 12:45:47 +0200

Hi all,

Searching in nano for regular expressions that contain the
beginning-of-line or end-of-line anchors (^ and $) does not
behave the same as in other editors.  For example, start nano
and type these two lines into a blank buffer:


(each five characters followed by <Enter>.  Then do:

^W  M-R  e+$  <Enter>

Then do M-W repeatedly -- it will find the string five times.
The same when searching for \$+$.  *But*... when wishing to
replace this latter regex with something, it will find the
string just once:  M-R  \$+$  <Enter>  x  <Enter>  N
However, when replacing e+$, it will ask five times when
answering N every time.  ...  Inconsistent.

In vim, searching for e\+$ will find just one occurrence.
In geany too.  In emacs I can't figure out how to search
normally for a regexp; Ctrl+Alt+S seems to find it just once.

So... what should nano do?  Match a regex with ^ and/or $
only once per line?  Or continue with the current behaviour
(about which no one seems to have complained in fifteen
years)?  (And then remove the special cases for ^\^+ and
\$+$, to make things consistent?)

In nano's code, the intent of regexp_bol_or_eol() seems to
have been to return TRUE when a regex contains a ^ or $
that works as a BOL or EOL anchor, but what it actually does
is check whether the regex, when interpreted, matches itself.
That is true only for special ones like ^\^+ and \$+$.

To make regexp_bol_or_eol() work in most cases, one could
simply check whether the regex starts with ^ or ends with $,
and return TRUE in those cases.  It would give false negatives
for regexes like (^e+|e+$), but would work for all the simple
ones.  Would that be good enough for a first approximation?
Or should nano stick to the old, multiple-matches behaviour?


-- - A fast, anti-spam email service.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]