gelakinetic
gelakinetic

Reputation: 523

Query Android's SQLiteDatabase using Regex

I am trying to fetch entries from a SQLiteDatabase in an Android program using the query function using the selection parameter. I have had success with simple pattern matching using the SQLite's LIKE and the % wildcard. Now I want to do more complex pattern matching using regular expressions.

According to the SQLite website, for the REGEXP operator to function, it must be user defined. Has anyone had any success creating use defined SQLite functions for Android's SQLiteDatabase? Or has anyone found another way to use regular expressions when searching through strings in a database?

Upvotes: 7

Views: 1785

Answers (1)

pawelzieba
pawelzieba

Reputation: 16082

As described here

The REGEXP operator is a special syntax for the regexp() user function. No regexp() user function is defined by default and so use of the REGEXP operator will normally result in an error message. If a application-defined SQL function named "regexp" is added at run-time, that function will be called in order to implement the REGEXP operator.

But there is GLOB which is little more advanced than LIKE.

Upvotes: 1

Related Questions