views:

37

answers:

2

The 'Like' is pretty simple it seems, it only supports ? and * I believe, kind of like old-school wildcards.

But I want to do this: Find all words that begin with a given range of characters... for example a-j.

So I got it to find all words that start with say, the letter j:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Name LIKE 'j*'"];

However, I can't figure out how to match all words that begin with a certain range, for example a-j: "Name LIKE '[a-j]*'" doesn't work..

any ideas how I might achieve this? Or will my only way be to do something like: "Name LIKE 'a*' OR Name LIKE 'b*' OR Name LIKE 'c*' OR Name LIKE 'd*' ... " cause that would be unfortunate...

Thanks!!!

+2  A: 

MATCHES will let you use regular expressions.

Wevah
A: 

Example & for easy copypasta:

//title starts with number
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title MATCHES '^[0-9].*'"];

//title starts with letter a-j or A-J
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title MATCHES '^[a-jA-J].*'"];
Katbyte