如何处理NSPredicate中的错误 [英] how handle error in NSPredicate
本文介绍了如何处理NSPredicate中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试匹配Data的正则表达式时。某些时候应用程序崩溃并出现错误
when i try to match regular expression for Data . sometime application crashes with error
这里是错误描述
'无法进行正则表达式匹配,原因:可以打开模式U_REGEX_INVALID_RANGE(字符串Ertyu,模式[aZ],案例0,正典0)'
'Can't do regex matching, reason: Can't open pattern U_REGEX_INVALID_RANGE (string Ertyu, pattern [a-Z], case 0, canon 0)'
这是我的代码
- (BOOL)isValidateString:(NSString *)inString ForRE:(NSString *)inRE {
BOOL isValidate=NO;
NSPredicate *thePredicate= [NSPredicate predicateWithFormat:@"SELF MATCHES %@", inRE];
isValidate= [thePredicate evaluateWithObject:inString];
return isValidate;
}
以及此方法RE是来自服务器。
and in this method RE is getting from server.
推荐答案
[aZ]
是无效范围因为 Z
在Unicode中的 a
之前。如果要匹配所有字母,请让服务器返回 [a-zA-Z]
。
[a-Z]
is an invalid range because Z
is before a
in Unicode. If you want to match all alphabets, make the server return [a-zA-Z]
.
这篇关于如何处理NSPredicate中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文