Thursday, 11 June 2009

XCode trailing whitespace

For all the other trailing-whitespace-haters out there, if you would like to remove trailing whitespace from all the files in your XCode project, do a global search replace (Shift+⌘+F) for the following regular expression:

[ \t]+$

In older versions of XCode you have to select all the results before hitting "Replace".


  1. check this out! its a plugin from google toolbox for mac that deletes end line whitespace, and adds eof line if there isnt any.

  2. GTM Xcode Plugin is a godsend! Thanks for the link!

  3. the problem with the google plugin for xcode is that it corrupts your undo buffer when it fixes your trailing whitespace. frustrating.

  4. I've found that this particular regex also matches lines that *only* have whitespace, at least in Xcode 3.2.6. Since I'd prefer to only remove trailing whitespace only on lines that also have non-whitespace characters, I needed something else.

    If you replace (?<=\S)[ \t]+$ with an empty string, it will match only lines that have trailing whitespace after one or more non-whitespace characters. Thanks for posting this tip!

  5. BTW there's an Xcode 4 version of the GTM plugin now. Checkout