3

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

For example, I would like to replace

varName->doWork()

with

::doWork(varName, 42)

whatever varName actually is.

Is there a straightforward way to do this?

1 Answer 1

3

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.

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

Your Answer

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

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