I want to use NSRegularExpression in my iPhone app, but Apple's documentation says that it was first available in iOS 4. Since iPads are still running on iOS 3.2 this means that my app would not be available for iPads -- correct? Is there any way to get around this? Or do I just need to wait until apple's iOS 4.1 release which should supposedly have iPad support?
+1
A:
NSPredicate supports regext so, depending on what you want to do, you can use NSPredicate. For example, this code tests for a valid eMail* in testString
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
BOOL notAValidEmail = ![emailTest evaluateWithObject:testString];
- yes, I know it's not a perfect test but it's pretty good.
Roger Nolan
2010-08-16 17:16:18
I was using RegexKitLite. The main advantage I found to switching was a **huge** improvement in performance.
Jason
2010-08-16 17:57:39
P.S. the solution I found was to use `NSClassFromString()` which allowed me to do different code for when the faster regex library is available.
Jason
2010-08-16 17:58:10
When you say "switching was a **huge** improvement in performance", do you mean switching from RegexKitLite to NSRegularExpression was a **huge** improvement, or the other way around?
johne
2010-08-17 16:55:07
I found that going from RegexKitLite to NSRegularExpression provided a very large speed boost. Presumably, Apple has really optimized their regex support.
Jason
2010-08-25 22:28:27