Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: replace-regex widget not replacing semicolons



On Jun 11,  2:49pm, Moritz Bunkus wrote:
}
} I'm using replace-regex bound to ALT+r, and it usually works quite
} well. Today I noticed that it doesn't replace semicolons, though. It
} looks like an off-by-one error when removing the char from the buffer.

It works for me with any replacement except those with "&" as the 2nd
or later character.  I think this is because "&" is a magic character
in regexp replacements, meaning a back-reference to the last string
that was matched?

There's a comment in replace-string-again:

    # The following horror is so that an & preceded by an even
    # number of backslashes is active, without stripping backslashes,
    # while preceded by an odd number of backslashes is inactive,
    # with one backslash being stripped.  A similar logic applies
    # to \digit.

("an even number of backslashes" includes zero of them).
 
What's happening with "&&" is that on entry to the regexp engine there
is no previous match, so "&" means itself.  Then the ";" is matched,
so now the second "&" means the matched part of the source string, and
becomes ";", and you end up with ";" =~ s/;/&&/ --> "&;".

Try with &\& or with p&q to see what I mean.  That the match pattern is
a semicolon doesn't matter.



Messages sorted by: Reverse Date, Date, Thread, Author