this post was submitted on 11 Nov 2023
12 points (100.0% liked)
Emacs
2190 readers
1 users here now
Our infinitely powerful editor.
founded 4 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
The regexp itself always looks forward, the BACKWARD argument just determines which direction the point should move after a match.
But what's so weird is that replace-regexp forwards with \w+ replaces all words, while replace-regexp backwards with \w+ replaces the characters individually.
@0v0 @emacs
Consider the string
abc
. From the end, moving backwards, when does it match\w+
, and what does it match? When it reachesc
, it matchesc
. And from the front, moving forwards? When it reachesa
, it matchesabc
. This is why it acts differently.Yes, I got that, that wasn't the weird part. The weird part is why the matcher is searching char-by-char backwards in the first place as opposed to skipping match-by-match.
I'll use "\b\w+", that seems to work well. \W\w+ was not good since it caught the spaces.
(Thanks for your patient repeated replies, BTW, I don't mean to come across as ungrateful.)
@0v0 @emacs