iOS-正则表达式的使用

1 目前使用的正则表达式分为两种,一种是ios自带的 NSPredicate,一种是开源的 RegexKitLite,下面将分别介绍两种方式的使用方法

NSPredicate
(用于快速查找,匹配)

 NSString * regex = @".*\\[.*\\]";//check [] for gps data 

 NSPredicate * pred      = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];

 BOOL isMatch            = [pred evaluateWithObject:dataStr];


RegexKitLite(需要加载 RegexKitLite.h .m文件
(用于字符串获取)

NSString * regexString = @"\\d{2}`\\d{2}'\\d{2}\"North";

latitude = [dataStr stringByMatching:regexString capture:1L];

NSLog(@"north: %@",latitude); //parse gps data north




你可能感兴趣的:(iOS-正则表达式的使用)