Using regular expressions in iPhone/Cocoa Touch apps
I thought I'd blogged about this earlier but apparently not: if you want to easily use regular expressions (regex) in your iPhone apps, take a look at the RegexKitLite project.
Adding it to your app simply involves two steps:
- Drag RegexKitLite.m and RegexKitLite.h to your Xcode project
- Under Project → Edit Project Settings → Other Linker Flags, add
-licucore
That's it!
The regular expression methods are set up as a category on NSString, so you can, for example:
NSArray *results = [@"Some string 123" captureComponentsMatchedByRegex:@"\d"]; NSString *coolString = [@"That's hot!" stringByReplacingOccurrencesOfRegex:@"h.t" withString:@"cool"];
Comments
by finty on 2010-02-26 15:49:37
by scranton mma on 2010-12-27 14:31:59