1

C-h h!

It happens quite often to me that I try to C-M-% a text. Thus I use query-replace-regexp interactively. So I enter the search regex and Emacs asks meekly for the replacement text, when in fact my search regex does not match any text!

Ideally, I would like to be signaled as soon as possible that my regex does not match.

Is there a way out of this?

1
  • 1
    You should check out the visual-regexp package! It shows a preview of matchs as well as a preview of the output! Commented Apr 19, 2016 at 19:24

1 Answer 1

3

One way to do this is to start with C-M-s, for isearch-forward-regexp, and interactively enter the regexp. That way, you'll see that it reaches the first match, and any further matches will be highlighted. Then, still in isearch mode, type C-M-%. The regexp from the isearch will automatically become the search regexp for the replacement command.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.