Use of Regular Expressions in IOS
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:@"123456ABCde"];