I want to replace a character inside a word, so I wrote:
(setq regexp "[ab]")
(and (re-search-backward regexp nil t 1)
(replace-match "c"))
This replaces a
or b
to c
as I wish, but I want to set a bound of it.
There is a BOUND
option with re-search-backward
.
How can I make the match only a word that is under the current cursor?
Thanks for @jackson I can write the function, but still it doesn't work properly.
(setq regexp ".*[ab].*")
(defun test-it ()
(interactive)
(save-excursion
(save-restriction
(narrow-to-region (progn (backward-word) (point))
(progn (forward-word) (point)))
(and (re-search-backward regexp)
(replace-match "c")))))
Thins function replaces ab
to ac
and ad
to cd
as I expected, but it doesn't replace ac
to cc
. Why?