tags:

views:

58

answers:

1

It does not seem possible to use REGEXP in a SQLite query in Android. If it is possible, please point me in the right direction.

Is there a way to use a LIKE condition to query for an expression at the beginning of any word in the result?

Example:


Entries:
1. Minimum
2. Aluminum
3. Last Minute

Query:
"min"

Desired Result
(1) Minimum
(3) Last Minute

NOT
(2) Aluminum


This is basically my current code, which would return (2)Aluminum:

public Cursor search(String query) {
    return mDb.query(TABLE, COLUMNS, KEY_NAME +" like ?", new String[] { "%"+query+"%" }, null, null, null);
}

Any help will be greatly appreciated!

+1  A: 

It's somewhat of a hack, but...

foo LIKE 'bar%' OR foo LIKE '% bar%'

might work for your needs (finding "bar" at the beginning of a word in "foo"). If you also want punctuation to serve as word delimiters, you'd have to add OR clauses for that as well (hence why it's a hack).

Amber
That works. Thanks Amber!
iPaulPro