Testing Regular Expressions for NSString


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. NSString *mystring = @"Hello World!";
  2. NSString *regex = @".*l{2,}.*";
  3.  
  4. NSPredicate *regextest = [NSPredicate
  5. predicateWithFormat:@"SELF MATCHES %@", regex];
  6.  
  7. if ([regextest evaluateWithObject:mystring] == YES) {
  8. NSLog(@"Match!");
  9. } else {
  10. NSLog(@"No match!");
  11. }

URL: http://www.stiefels.net/2007/01/24/regular-expressions-for-nsstring/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.