I like to think it’s entirely a lifestyle choice that Cocoa exposes no regular expression API to developers. It’s probably the same motivation behind making Xcode such a tortuous IDE – Apple just don’t want the rabble writing Mac apps.
But, nevertheless, we plug away, and of the half-dozen available regex libraries out there, I settled on RegexKitLite. It’s dead easy to integrate (drop two files in your project) and relies on a built-in (but technically unsupported for development, if not verboten) OS X library called the International Components for Unicode.
The RKL docs show you two ways of referencing it, but neither seemed right to me, and it turns out that Xcode (3.1 at least) makes it even easier.
- Right-click on each target in which you need regular expressions.
- Click on the ‘+’ under Linked Libraries.
- Click on the drop-down to filter to ‘Dylibs’.
- Scroll down to libicucore.dylib and add it.
After that you’re all set.