如何使用 NSPredicate 在 ios 中查找以数字或特殊字符开头的 NSString?

How to use NSPredicate to find an NSString begins with numbers or special characters in ios?

请问如何使用 NSPredicate 查找 NSString beginsWith 数字或其他特殊字符(但不以字母开头)?我想对包含任意数字和特殊字符的数组名称进行排序。预先感谢您的帮助。

您应该可以使用 MATCHES 关键字:

[NSPredicate predicateWithString:@"self MATCHES [^a-zA-Z]+.*"]

您可以在这里找到更多文档:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html#//apple_ref/doc/uid/TP40001795-215868

以及如何在此处定义正则表达式的定义:

http://userguide.icu-project.org/strings/regexp