Use of Regular Expressions in IOS
Luo chaohui (http://www.cnblogs.com/kesalin)
This article follows the "signature-non-commercial use-consistency" creation public agreement
In iOS, nspredicate can be used to process regular expressions. The related information is as follows:
Nspredicate:
Http://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/predicates.html
Predicate format strings:
Http://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html
ICU regular expression rules:
Http://www.icu-project.org/userguide/regexp.html
In iOS, we use the string comparison function of nspredicate for regular expression processing. The comparison keyword is:Matches
Next, we will list a regular expression that matches 6-15 strings consisting of letters/numbers to see how nspredicate works:
Nsstring * RegEx =@"(^ [A-Za-z0-9] {6, 15} $)";
Nspredicate * Pred = [nspredicate predicatewithformat:@"Self matches % @", RegEx];
Bool ismatch = [Pred evaluatewithobject:@"123456 ABCDE"];