ocross
ocross

Reputation: 613

REGEXP in Android SQLite

I am trying to get a REGEXP to work with android SQLite in the contacts database. What I am trying to do is do whole word matching for the contacts display name to look for words such as "uncle" or "aunt" even when the display name may be something like "uncle sam" or "aunt julie". However whenever I try using REGEXP I get the error

android.database.sqlite.SQLiteException: ICU error: uregex_open(): U_ILLEGAL_ARGUMENT_ERROR (code 1)

This is a simplified version of what I am trying to do in the query:

whereBuffer.append(ContactsContract.Contacts.DISPLAY_NAME).append(" REGEXP ").append("'[[:<:]]uncle[[:>:]]'");

Upvotes: 0

Views: 1171

Answers (1)

Bob Snyder
Bob Snyder

Reputation: 38289

The SQLite documentation explains that the REGEXP operator is a special syntax for the regexp() user function. In Android, no regexp() user function is defined.

For the matching you want to do, the LIKE operator should be sufficient:

(ContactsContract.Contacts.DISPLAY_NAME).append(" LIKE ").append("'%uncle%'");

If you need more general pattern matching, consider using the GLOB operator. The GLOB operator is similar to LIKE but uses the Unix file globbing syntax for its wildcards. Also, GLOB is case sensitive, unlike LIKE.

Upvotes: 2

Related Questions