The definition of regexp-replace specifies the meanings of ‘pre and ‘post as substitution arguments.
What I expect is that ‘pre/‘post will transform into
(substring string start (regexp-match-submatch-start match 0))
(substring string (regexp-match-submatch-end match 0) end)
However, looking at the chibi implementation (the only one I’ve found after 10 minutes of searching), what these transform into is
(substring string 0 (regexp-match-submatch-start match 0))
(substring string (regexp-match-submatch-end match 0) (string-length string))
I suspect that this is a bug, given this sentence in the description:
The optional parameters start and end restrict both the matching and the substitution, to the given indices, such that the result is equivalent to omitting these parameters and replacing on (substring str start end)
.
But I’d appreciate confirmation of this. It might also be good to clarify what happens here.
The meaning of ‘pre/‘post is even more confusing in regexp-replace-all. Chibi’s implementation again substitutes between zero:match-start and match-end:length, for each of the replacements. Again this seems like a bug.
I can think of two other interpretations: one is to just do what Chibi does, but use start and end rather than zero and length. The other is to define ‘pre to mean between the end of the previous match and the start of this match, and ‘post to mean between the end of this match and the start of the next (using start for the first match and length for the last).
Each of these is plausible but it’s not clear to me what was intended. Could I get some guidance on this?