Regular Expressions in Objective-C

This class allows you to use very powerfull regular expressions (because it’s based on regexec from C) in an object oriented way.
Thanks to the post of David Teare, I finally find a very easy and powerfull solution for using regular expressions in Objective-C. David’s code only returns a boolean to indicate if the NSString was matching the given regular expression. I improve its method by returning a NSMutableArray with the different sub-expressions that lead to a match. Unfortunately I wasn’t able to return nil when the sub-expression doesn’t produce a match, instead I return the empty NSString @””.

Download Regular Expression Source Code

[Updated the 16.05.2007] Thanks to everybody for you remarks, I updated the source file accordingly. I also add a example script to demonstrate the use of the method.

Download Regular Expression Source Code version 1.1

[Updated the 01.01.2008] After receiving a reader’s mail about the code’s licencing, I clarify the situation and add the GPL licence in the header as well as the full licence in the package.

Download  Regular Expression Source Code version 1.1

[Update 22.02.2009] Hey I just discovered that TwitterFon, YMail and swisssms are using this class. Cool isn’t it.

[Updated the 08.04.2009] Bugfix the behavior when working on NSString with UTF8 encoded chars. Thanks to Ian Atha & soniccat for the correction

Download Regular Expression Source Code version 1.2