This must be a duplicate. But with so many NSPredicate questions out there, I can't find the right one.
I have a list of Core Data objects that contain a compositeName
field. A name like 'Emily Blunt' could be in there. I want to search the list using an NSPredicate
that will let me search for "Em" but also for "Bl" and then have this name show up in the fetched results.
This must be super easy, but as you'd guess, I'm not seeing it. My dysfunctional attempt at an NSPredicate with a regular expression looks like this:
[NSPredicate predicateWithFormat:@"compositeName MATCHES[cd] '.*(?<=^|\\s)%@.*'", query];
My thought for this regular expression were:
- any number of characters before
- negative lookbehind spaces or beginning
- the query
- any number of characters after
But it's not working. I'm not getting any results. How do I fix this?
P.S. If there's an NSPredicate solution without Regular Expressions that would suit my purpose too.