EmptyStack EmptyStack - 4 months ago 12x
iOS Question

Find/Replace in Xcode using Regular Expression

I have the following function calls at several places in my class.

[myClass doOperationOne];
[myClass doOperationTwo];
[myClass doOperationThree];

In those lines, I want to search for the following,

[myClass doOperationOne
[myClass doOperationTwo
[myClass doOperationThree

And replace them with the following, (by appending
WithOptions:[Permissions isOptionsAvailable]

[myClass doOperationOneWithOptions:[Permissions isOptionsAvailable]];
[myClass doOperationTwoWithOptions:[Permissions isOptionsAvailable]];
[myClass doOperationThreeWithOptions:[Permissions isOptionsAvailable]];

How can I do this using single Regular Expression Find/Replace?


Somehow I've managed to find the answer (which is enough for my need here) by referring the post: http://www.cocoabuilder.com/archive/xcode/273123-how-to-use-regular-expressions-in-xcode-find-replace.html, and trial and error method.

My Find string is:

(\[myClass.myMethod )(.*)(\];)

And, my Replace string is:

\1\2WithOptions:[Permissions isOptionsAvailable]\3

Please post if there is any better way than this..