我在我的应用中使用了coredata,
我可以用起始字母
搜索所有实体NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name MATCHES '^[hH].*'"];
//sort descriptor!
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSArray *companyProducts = [Company allWithPredicate:predicate sortDescriptors:@[sortDescriptor]];
Company *theCompany;
NSLog(@"tus companies number:: %d", companyProducts.count);
for (theCompany in companyProducts) {
NSLog(@"tus companies:: %@", theCompany.name);
}
所以在这种情况下,无论是大写还是大写,我都会得到所有以h开头的公司......
但是如果我需要搜索多个字母的匹配项?无论是大写还是大写,
例如寻找:
超 晓星
所以我需要知道如何构建我的正则表达式?在我的房产上搜索n个字符?
谢谢!
答案 0 :(得分:4)
尝试
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name BEGINSWITH [c] %@",@"H"];