Why does replace-regexp backwards work so differently?
Why does replace-regexp backwards work so differently?
Why does replace-regexp backwards work so differently?
C-u - M-x replace-regexp \w+
The -
prefix arg replaces backwards but it hits one char at a time, as if the plus sign weren't there. The same replacement forwards (without the prefix arg) does hit one word at a time. What's going on, @emacs@lemmy.ml?
Because once it hits the ultimate character of a word,
\w+
matches that (single) character, next time it matches the penultimate character, etc. You'd need\W\w+
to make it look far enough back to the beginning of the word.So it's literally looking at the regexp backwards and forwards at the same time 😵💫
@0v0
The regexp itself always looks forward, the BACKWARD argument just determines which direction the point should move after a match.