I sometimes need to do replacements which would involve using matched parts for the output.

For example, I would like to replace



::doWork(varName, 42)

whatever varName actually is.

Is there a straightforward way to do this?

1 Answer 1


It's doable. M-x query-replace-regexp:

  • from: ^\(\w+\)->\([^(]+\)()
  • to: ::\2(\1, 42)

But if it's a recurring pattern, it's best to solidify it in a function, instead of entering the regex each time.

  • 1
    Hmmm, isn't it ::\2(\1, 42)?
    – Nsukami _
    Commented Jan 2, 2015 at 23:01
  • Oops, you're right.
    – abo-abo
    Commented Jan 2, 2015 at 23:06

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.