Iphone开发使用正则表达式

1. 第三方库   RegexKitLite的类库

   见  http://www.cnblogs.com/chenfulai/archive/2011/08/10/2133642.html  

没有去验证,我的项目并不需要多复杂的匹配.没有必要引入

2. NSPredicate    ios3.0开始支持

  NSString * regex        = @"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}"; 
NSPredicate
* pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL isMatch
= [pred evaluateWithObject:@"1234@fdsfsd.1"];
if(isMatch){
NSLog(
@"匹配");
}
else{
NSLog(
@"不匹配...");
}



3. NSRegularExpression   ios4.0开始支持

见 http://285746555.blog.51cto.com/2966432/554755  



原文地址:https://www.cnblogs.com/jifsu/p/2181721.html