I am terrible at remembering regular expression syntax. When replacing in by buffer with a regexp, I would like Emacs to highlight the possible matches while I am typing the regexp, so that I can see on the fly whether I am getting what I want. Is there any way of achieving this?
I just noticed that my answer is valid for Emacs 29.0.50, but not for Emacs 28.1. Unfortunately, I can not easily find when this was added.
This is default behavior when using
Emacs does not show you the result when typing the new pattern (for replacement). However, when using vim style substitution via the [evil]package, then you will also see a preview of the result of the replacement. You can also use it without using evil-mode, by installing and loading evil and then do
M-x evil-ex (which you could bind to your preferred key).