Reputation: 1047
I have this string:
<td align="right"><span> 19:45 </span></td>
I want to use a NSPredicate on it to search for the 19:45 part but every possible combination I tried returns nothing! I'm kinda losing my marbles here so please help!
Things i've tried:
NSString *timeStringPredicate = @"[0-9]:[0-9]";
NSPredicate *timeSearch = [NSPredicate predicateWithFormat:@"SELF like %@", timeStringPredicate];
if ([timeSearch evaluateWithObject:dayText]) {
NSLog(@"This is a time");
}
Or in these possibilities:
NSString *timeStringPredicate = @"[0-9]\\:[0-9]";
NSString *timeStringPredicate = @"*[0-9]:[0-9]*";
NSString *timeStringPredicate = @"*[0-9]\\:[0-9]*";
NSString *timeStringPredicate = @"*.[0-9]:[0-9].*";
NSString *timeStringPredicate = @"*.[0-9]\\:[0-9].*";
And about everything else.
Help!
Upvotes: 1
Views: 455
Reputation: 11
Try to do this:
NSString *timeStringPredicate = @".*\\:[0-9].*";
NSPredicate *timeSearch = [NSPredicate predicateWithFormat:@"SELF matches '%@'", timeStringPredicate];
Upvotes: 0
Reputation: 73936
like
doesn't use regexp syntax. For that, you need to use matches
instead. See The Predicate Programming Guide for details.
NSString *timeStringPredicate = @".*\\:[0-9].*";
NSPredicate *timeSearch = [NSPredicate predicateWithFormat:@"SELF matches %@", timeStringPredicate];
Upvotes: 1