I couldn't find anything that specifically addressed how to find square brackets in predicates on Stack Overflow or on Google so I thought I would post it here and see if anyone can explain the solution.
NSString *mstr = @"fasd[981db7007771ffa3]dfaads";
NSString *test =@".*\\[[0-9,a-f]{16}\\].*";
//NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*\\\\[[0-9,a-f]{16}\\\\].*'"]; //works
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", test];
if ([pred evaluateWithObject:mstr]) {
NSLog(@"Yes");
}
It seems that when escaping the brackets in-line you need four backslashes but if you put it in a string you only need two. Not clear why that is the case.