I've been using pandoc and emacs to convert beamer presentations to markdown format. In the beamer presentations we highlighted certain code in example code blocks red. Pandoc has left me to get rid of these by hand. I have been trying to use M-x replace-regexp to find all $\alert{...}$ and replace it with ....

I keep getting an error saying:

Invalid use of '\' in replacement text

Here is an example of what I'm trying to replace

$\alert{bool has_burnup;}$
$\alert{const Variable Value & _burnup;}$


Should be replaced as:

bool has_burnup;
const Variable Value & _burnup;


Here is what I'm currently trying

M-x replace-regex <RET> \$\\alert{.+}\$ <RET> [^{\}]+(?=})

These regexp work when using an online testing environment. Why won't it work in emacs?

1 Answer 1


Text to keep needs parenthesis. That works here:

M-x query-replace-regexp RET $\\alert{\(.+\)}.* RET \1 RET

From a program use re-search-forward and replace-match

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.