在XCode 8中,如何使用正则表达式搜索替换来更改字符的大小写?

时间:2022-05-25 16:49:28

I inherited an Objective C project with a bunch of methods named things like "getMerchantSettings". Of course in Objective C (unlike Java) it is unconventional to use the word "get" in the method name for getters, since it makes them incompatible with auto-synthesized property getters, etc.

我继承了一个Objective C项目,其中包含一些名为“getMerchantSettings”的方法。当然,在Objective C(与Java不同)中,在getter的方法名称中使用“get”这个词并不常见,因为它使它们与自动合成的属性getter等不兼容。

I can globally search my project to find all such offending method names using a regex pattern like get([A-Z]). In SublimeText I can replace all these with \L$1 and it will change everything like "getMerchantSettings" to just say "merchantSettings"; the \L will make the "M" character into the lower case "m" when it replaces it.

我可以全局搜索我的项目,使用像get([A-Z])这样的正则表达式模式来查找所有这些有问题的方法名称。在SublimeText中,我可以用\ L $ 1替换所有这些,它会将“getMerchantSettings”之类的内容更改为“merchantSettings”;当L取代它时,\ L将把“M”字符变为小写“m”。

However in XCode's version of regex, \L and \l both do not work. What is the regex replacement pattern to use in XCode 8 to make it change the case of whatever it's replacing? Would prefer not to have to use a separate text editor for things like that. Thanks!

但是在XCode版本的正则表达式中,\ L和\ l都不起作用。什么是在XCode 8中使用的正则表达式替换模式,以使它改变它所取代的任何东西的情况?不希望不必为这样的事情使用单独的文本编辑器。谢谢!

1 个解决方案

#1


3  

XCode 8 can't do that for you unfortunately. As you have perl, you can open a terminal, cd to your repo and run this:

不幸的是,XCode 8无法为您做到这一点。正如你有perl,你可以打开一个终端,cd到您的仓库并运行:

find . -name *.[EXTENSION] -exec perl -i.bak -pe 's/get([A-Z])/\L$1/' {} \;

This will generate a backup of your files (.bak files) and change your getters to the needed format.

这将生成您的文件备份(.bak文件)并将您的getter更改为所需的格式。

#1


3  

XCode 8 can't do that for you unfortunately. As you have perl, you can open a terminal, cd to your repo and run this:

不幸的是,XCode 8无法为您做到这一点。正如你有perl,你可以打开一个终端,cd到您的仓库并运行:

find . -name *.[EXTENSION] -exec perl -i.bak -pe 's/get([A-Z])/\L$1/' {} \;

This will generate a backup of your files (.bak files) and change your getters to the needed format.

这将生成您的文件备份(.bak文件)并将您的getter更改为所需的格式。