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?


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 _
    Jan 2 '15 at 23:01
  • Oops, you're right.
    – abo-abo
    Jan 2 '15 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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