閱讀116 返回首頁    go 阿裏雲 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拚接字符串必須用雙引號