How can I use regex to get data from sqlite?

I want to search in a column containing String, like "I will have #dinner with @Akki on her # Bday. I am looking for it now, but it notices the work. While variable search has a value like #dinner. Thanks.

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

0
source share
3 answers

After a long R&D, I came to the conclusion that I cannot use REGEXP directly. then i tried  Cursor c = db.rawQuery("SELECT * FROM TODOS WHERE tag LIKE '%"+search+"%' ",null);

and it worked fine. Thanks to everyone.

-1
source

Try using

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

See Android SQLite Link :

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

selectionArgs - ? where , selectionArgs. .

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

All Articles