开发者

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 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!


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜