【问题标题】:How to use NSPredicate to find an NSString begins with numbers or special characters in ios?如何在ios中使用NSPredicate查找以数字或特殊字符开头的NSString?
【发布时间】:2015-06-26 20:13:31
【问题描述】:

能否请您帮忙,如何使用 NSPredicate 查找 NSString 的开头为数字或其他特殊字符(但不能以字母开头)?我想对包含任何数字和特殊字符的数组名称进行排序。提前感谢您的帮助。

【问题讨论】:

  • NSDiacriticInsensitivePredicateOption 可用于过滤特殊字符
  • @"SELF MATCHES %@",@"[^a-zA-Z0-9]+.*" ?
  • 谢谢你。它对我有用。我犯的错误不包括“+。”。我曾用作“[^A-Za-z]*”

标签: ios nspredicate


【解决方案1】:

您应该可以使用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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 2020-02-16
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多