开发者

NSRegularExpression - no iPad support?

开发者 https://www.devze.com 2023-01-12 06:48 出处:网络
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 a

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 a开发者_如何学Govailable 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?


I use RegexKitLite on iPhoneOS < 3.2


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消