SQLite LIKE alternative for REGEXP, Match Start of Any Word
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 MinuteQuery:
"min"Desired Result
(1) Minimum (3) Last MinuteNOT
(2) AluminumThis 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!
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).
精彩评论