//对数组进行过滤
NSArray *array = [[NSArray alloc]initWithObjects:@"beijing",@"shanghai",@"guangzou",@"wuhan",nil];
NSString *string = @"ang";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF CONTAINS %@",string];
NSLog(@"%@",[array filteredArrayUsingPredicate:pred]);
//判断字符串是否为字母
NSString *regex = @"[A-Za-z]+";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
NSString *aString=@"nkl";
if ([predicate evaluateWithObject:aString]) {
NSLog(@"是字母");
}else
{
NSLog(@"不是字母啊");
}
原文链接:https://www.f2er.com/regex/360887.html