Re: NSPredicate regex
Re: NSPredicate regex
- Subject: Re: NSPredicate regex
- From: martin halter <email@hidden>
- Date: Tue, 16 Feb 2010 16:55:55 +0100
hello list
I'd like to check a bunch of Strings if they contain the word "cache". The strings are actually paths and I check the last path component. I tried to use CoreText to detect words, but the API was a bit overwhelming. So I tried NSPredicate which worked like a charm. It detects the word as of word boundaries are not characters (numbers, space, dash and everything else).
{
NSString *regex = @"(?:.*[\\s\\W0-9])*cache(?:[\\s\\W0-9].*)*";
NSPredicate * cacheStringRegex = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
...
NSURL url; // assume this exists, comes from a directory enumerator
if ( [cacheStringRegex evaluateWithObject:[url lastPathComponent]] ) {
NSLog(@"found cache directory");
}
}
sadly, there is an error in the regex and i cannot find it. I had three strings where the CPU went to 100% and the app did not recover. here the three strings (yes, those are directory names outside of NSCachesDirectory, i was surprised too :-)
com.mini.cuckooClock.Widget.7561A773F51A798326D350FE0D5617D29C3D222A.1
binarygod-BGHUDAppKit-d240cfb1a1bc155e961db145dd94e960099711b2
11) mit cachedPreferredFrameSize, ZF_SPOTLIGHT_CACHE_RESULTS, ZF_GLOBAL_SCALE = 0,707, INITIAL_BACKGROUND, CACHE_FOR_PREVIEWS
Respect to everybody who is fluent in regex. Respect to everybody who knows another approach.
regards & thank you in advance
mahal
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden