我有这个字符串:
<td align="right"><span> 19:45 </span></td>
我想在它上面使用NSPredicate来搜索19:45部分,但我试过的每一种可能的组合都没有返回!我有点丢失我的弹珠,所以请帮忙!
我尝试过的事情:
NSString *timeStringPredicate = @"[0-9]:[0-9]";
NSPredicate *timeSearch = [NSPredicate predicateWithFormat:@"SELF like %@", timeStringPredicate];
if ([timeSearch evaluateWithObject:dayText]) {
NSLog(@"This is a time");
}
或者在这些可能性中:
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].*";
关于其他一切。
帮助!
答案 0 :(得分:1)
like
不使用regexp语法。为此,您需要使用matches
代替。有关详细信息,请参阅The Predicate Programming Guide。
NSString *timeStringPredicate = @".*\\:[0-9].*";
NSPredicate *timeSearch = [NSPredicate predicateWithFormat:@"SELF matches %@", timeStringPredicate];
答案 1 :(得分:0)
尝试这样做:
NSString *timeStringPredicate = @".*\\:[0-9].*";
NSPredicate *timeSearch = [NSPredicate predicateWithFormat:@"SELF matches '%@'", timeStringPredicate];