RosettaCodeData/Task/Regular-expressions/Objective-C/regular-expressions-1.m
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

9 lines
302 B
Objective-C

NSString *str = @"I am a string";
NSString *regex = @".*string$";
// Note: the MATCHES operator matches the entire string, necessitating the ".*"
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if ([pred evaluateWithObject:str]) {
NSLog(@"ends with 'string'");
}