使用正则表达式在Xcode中查找/替换 [英] 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
并用以下内容替换它们(通过附加 WithOptions:[Permissions isOptionsAvailable]
)
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?
推荐答案
不知何故,我通过引用帖子找到答案(这对我的需要来说足够了): http://www.cocoabuilder.com/archive/xcode /273123-how-to-use-regular-expressions-in-xcode-find-replace.html ,以及试错法。
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.
我的查找字符串是:
(\[myClass.myMethod )(.*)(\];)
而且,我的替换字符串是:
\1\2WithOptions:[Permissions isOptionsAvailable]\3
如果有更好的方式,请发布..
Please post if there is any better way than this..
这篇关于使用正则表达式在Xcode中查找/替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!