阅读116 返回首页    go 技术社区[云栖]


NSPredicate匹配中文正

在 iOS 中,我们使用 NSPredicate 的字符串比较功能来进行正则表达式处理,其比较关键字为:MATCHES

下面,列举一个匹配6-15个由字母/数字组成的字符串的正则表达式,来看看 NSPredicate 的具体使用:

    

NSString * regex        = @"(^[A-Za-z0-9]{6,15}$)";

NSPredicate * pred      = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];

BOOL isMatch            = [pred evaluateWithObject:@"123456ABCde"];


iOS 中可以通过NSPredicate 来处理正则表达式。相关资料如下:

NSPredicate 苹果官方文档:
https://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/predicates.html

Predicate format strings:
https://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html

ICU 正则表达式规则:
https://www.icu-project.org/userguide/regexp.html

最后更新:2017-04-02 16:48:06

  上一篇:go 一个游戏程序员的学习资料
  下一篇:go Json拼接字符串必须用双引号