ios核心数据谓词搜索单词相似

ios核心数据谓词搜索单词相似,ios,objective-c,core-data,Ios,Objective C,Core Data,我在应用程序中使用coredata 我可以用起始字母搜索所有实体 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name MATCHES '^[hH].*'"]; //sort descriptor! NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selecto

我在应用程序中使用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个字符吗

谢谢

试试看

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name BEGINSWITH [c] %@",@"H"];
试一试

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name BEGINSWITH [c] %@",@"H"];

您可以使用BEGINSWITHhi@Anupdas进行尝试,我使用nspreditate*谓词=[nspreditate preditewithformat:@“name BEGINSWITH'H'”;但问题是如何使其与小写或小写与大写组合使用?谢谢您可以使用BEGINSWITHhi@Anupdas进行尝试,我使用nspreditate*谓词=[nspreditate preditewithformat:@“name BEGINSWITH'H'”;但问题是如何使其与小写或小写与大写组合使用?谢谢嗨,谢谢,很好!,允许时将接受!,但另一个问题,这是正则表达式吗?所以我学习如何构造这个谓词?tnx@MaKo抱歉,我不确定他们是如何做到这一点的。但是,您可以在NSpredicate中查看更多可用选项。谢谢,非常好!,允许时将接受!,但另一个问题,这是正则表达式吗?所以我学习如何构造这个谓词?tnx@MaKo抱歉,我不确定他们是如何做到这一点的。但您可以在NSPredicate中参考此选项以了解更多可用选项