NSPredicate带有问号崩溃 [英] NSPredicate crashed with question mark

查看:914
本文介绍了NSPredicate带有问号崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSPredicate看起来像这样...

I have a NSPredicate which looks like this ...

NSPredicate *predicate = [NSPredicate predicateWithFormat : @"keyword MATCHES[c] %@", theKeyword]; 

其中
theKeyword = @?;

谓词坠毁时出现以下异常...

The predicate crashed with the following exception ...

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't do regex matching, reason: (Can't open pattern U_REGEX_RULE_SYNTAX (string D;rdz;oirnodzirngzdorngzdorngzdrjgnz@dorjn
Isdjfij
Fisdjfisj
Jsifjsijfs
Ifjifjs
Isjfidsj
Fjisjfi
, pattern ?, case 1, canon 2))'

有人知道为什么它不工作吗?
感谢所有帮助>

Does anybody know why it just won't work? Thanks for all the help >"<

推荐答案

我不熟悉 NSPredicate ,但如果应该是正则表达式,那么它是无效的。问号是一个量词,意思是

I'm not familiar with NSPredicate, but if ? is supposed to be a regular expression, then it's invalid. The question mark is a quantifier, meaning "zero or one instances of the previous token" - and there is no token to repeat. What do you want your regex to do?

如果你想匹配一个字面的问号,那么你的正则表达式需要使用反斜杠转义它(regex literal: \?,regex string: \\?

If you want to match a literal question mark, then you need to escape it using backslashes (regex literal: \?, regex string: \\?)

这篇关于NSPredicate带有问号崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆