0

I have a lot of occurances of something =like_this= and I need to replace the both equals signs with this character: `

After looking at this question I thought the following would do it:

M-x query-replace-regex =\(.*\)?= RET `\1`

That doesn't seem to do it, though. Any suggestions?

1 Answer 1

2

To create a capture group, you need to backslash the parentheses \(...\). That's convenient in Emacs, because you often process Elisp, and you don't have to backslash its parentheses.

Also note that the question mark follows the asterisk immediately, as it modifies its greediness.

=\(.*?\)=
`\1`
3
  • Sorry, that's a typo on my part. I'll edit my question. It still doesn't work with them escaped, though.
    – Alex
    Commented Apr 6, 2016 at 22:48
  • @Alex: Check the update.
    – choroba
    Commented Apr 6, 2016 at 22:49
  • Ah, it was the question mark placement. Thanks, this works now. Makes sense that the question mark needs to be inside the parens, too. Thanks!
    – Alex
    Commented Apr 6, 2016 at 22:52

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.