// // NSStringAdditions.m // JSRunIpodHelperApp // // Created by Jonathan Saggau on 10/31/06. // Copyright 2006 Jonathan Saggau. All rights reserved. // #import "NSStringAdditions.h" BOOL stringMatchesPattern(NSString * string, NSString * regex) { NSString *testRegex = [[NSString alloc] initWithFormat:@"SELF MATCHES '%@'", regex]; NSPredicate *regexPredicate = [NSPredicate predicateWithFormat:testRegex]; [testRegex release];// the predicate has retained testRegex return ([regexPredicate evaluateWithObject:string]); } @implementation NSString (NSStringAdditions) - (BOOL) matchesPattern:(NSString *) regex; { return stringMatchesPattern(self, regex); } @end