我如何使用 Regex 从 sqlite 获取数据?

How can i use Regex to get data from sqlite?

我想在包含字符串的列中搜索,例如“我将与@Akki 共进晚餐#Bday.I 我现在正在这样搜索,但它确实有效。 而变量搜索具有像#dinner 这样的值。谢谢。

selectionArgs = new String[] {"'"+search+"'"}; String qur="SELECT * FROM TODOS WHERE fullnote REGEXP"; Cursor c = db.rawQuery(qur,selectionArgs);

尝试使用

String[] selectionArgs = new String[] {"%"+search+"%"};
Cursor c = db.rawQuery("SELECT * FROM TODOS WHERE fullnote LIKE ?",selectionArgs);

参见Android SQLite reference

public Cursor rawQuery (String sql, String[] selectionArgs)

selectionArgs - You may include ?s in where clause in the query, which will be replaced by the values from selectionArgs. The values will be bound as Strings.

selectionArgs =  new String[] {search};
    Cursor c = db.rawQuery("SELECT * FROM TODOS WHERE fullnote LIKE '%?%'",selectionArgs);

经过长时间的研发,我发现我不能直接使用 REGEXP。 然后我试过了 Cursor c = db.rawQuery("SELECT * FROM TODOS WHERE tag LIKE '%"+search+"%' ",null);

而且效果很好。 谢谢大家