In Xcode 8, how do you use regex replacement to change the character case?

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

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

However, in the regex version, Xcode \ L and \ l both do not work. What is the regular expression replacement pattern to use in Xcode 8 so that it changes the case of what it replaced? Prefer not to use a separate text editor for such things. Thank!

+4
source share
1 answer

Xcode 8 cannot do this for you, unfortunately. Since you have perl, you can open a terminal cdfor your repo and run this:

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

This will back up your files .bakand change your getters to the desired format.

+3
source

Source: https://habr.com/ru/post/1658034/


All Articles