0

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[[:>:]]'");

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This was also my first thought but certain of the matching cases are names like "ma" so matching '%ma%' would return a lot of names that include 'ma' in them. The GLOB operator seems like I could use it to get what I am looking for however I wish it were not case sensitive as to make it not case sensitive would be require me to convert all works to a regex to match upper and lowercase of all the characters in the word.
Any news on that? Some information about if Android plans to add one, and if already implemented, from which version on?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.