I having a difficulty with regex, I have a table products that of one of it`s field is a period. I want to filter records by a period the user entered in my application. for example the period might be 2006-2012 or just 2006-
I want to filter all the records that contain only the pattern 2006-
I tried many examples but unfortunately nothing works properly
this is my code
Cursor c = rDB.rawQuery("select title,price from Products,UserProducts where UserProducts.product_code=Prodcuts.product_code and USER_EMAIL=? and Products.period like '%[0-9]+%' group by UserSeries.product_code order by Products.title asc", new String[]{email});
while(c.moveToNext())
{
//save the records
}
LIKE
does not work with regexps.To use regular expression matching, use the
REGEXP
operator. Note that by default theREGEXP
operator is not implemented, even though the syntax supports it.For simpler matching needs you can also consider
GLOB
.You don't need a regular expression for that.
will match anything where
period
starts with the string2006-
.will match anything where
period
ends with the string-
.