views:

174

answers:

3

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
+2  A: 

I use RegexKitLite on iPhoneOS < 3.2

vikingosegundo
I was using RegexKitLite. The main advantage I found to switching was a **huge** improvement in performance.
Jason
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
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
I found that going from RegexKitLite to NSRegularExpression provided a very large speed boost. Presumably, Apple has really optimized their regex support.
Jason
A: 

fine man, thank you , more easy than a nsregularexpression.

avatarT