Xcode renaming is good, but in some cases it can’t help.
Often, I go back to using Atom to find and replace, using regex.
- Open a file (or a directory if multiple files) in Atom
CMD+Cto copy the string to find
CMD+SHIFT+Fto bring up Find panel
When you bring up Atom’s Find panel, the copied string will be automatically populated in the find field, and best of all – automatically escape regex characters!
\ added in the Find textfield:
NOTE: Make sure the regex mode (the
.* option) is enabled.
2. Captured Group
Using the following example, we want to find some functions with string, and refactor them to a simple form:
// Original disease.cure(with: "vaccine") disease.cure(with: "mask") // To replace and become vaccine.asCure mask.asCure
To do that, we need to add captured group for any strings (vaccine, mask, etc). We do that with
(.*?), capturing the shortest possible string.
We edit Find to:
Finally, we replace with:
The first captured group is
$1. If you have more captured groups, you can use