iOS中有三种方式来实现正则表达式的匹配。现在将他们都记录在这里:
1.利用NSPredicate(谓词)匹配
例如匹配有效邮箱:
NSString *email = @“nijino_saki@163.com”;
NSString *regex = @[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4};
NSPredicate *predicate = [NSPredicate predicateWithFormat:@SELF MATCHES %@, regex];
BOOL isValid = [predicate evaluat