我正在我的应用程序中使用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开头,不管是大写还是小写...
但是如果我需要搜索多个字母的匹配项呢?无论小写还是大写,
例如,查找:
Hyper hyosung
所以我需要知道如何构造我的正则表达式?在我的物业上搜索n个字符?
谢谢!
发布于 2013-06-20 12:52:24
尝试使用
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name BEGINSWITH [c] %@",@"H"];https://stackoverflow.com/questions/17205469
复制相似问题