So, I am trying to search the master data. Say mine CoreDatahas two fields that NSString(we will call them foo and bar). The user gives an indication of which field to search and the search string. I am using this code now:
NSString *format = [NSString stringWithFormat:@"(%@ matches[c] %@)", field, @"%@"];
NSString *pattern = [NSString stringWithFormat:@".*\\b%@.*", partialString];
NSPredicate *predicate = [NSPredicate predicateWithFormat:format, pattern];
[fetchRequest setPredicate:predicate];
The field is passed as "foo" or "bar". A partial string is a search string. If bar contains "Grand Poobah", I want it to match when "Poo" is the query string (but not when it is "oobah", so I have \ b in the regex).
But the problem I have is if someone gives the request "Poo (" it crashes because it is interpreted as part regex.
Is the best route to simply remove all special characters in partialString before creating the template? Or is there another way I have to build a predicate?
bryan source
share