Reputation: 123
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
}
Upvotes: 2
Views: 5076
Reputation: 152817
Products.period like '%[0-9]+%'
LIKE
does not work with regexps.
To use regular expression matching, use the REGEXP
operator. Note that by default the REGEXP
operator is not implemented, even though the syntax supports it.
For simpler matching needs you can also consider GLOB
.
I want to filter all the records that contain only the pattern 2006-
You don't need a regular expression for that.
Products.period like '2006-%'
will match anything where period
starts with the string 2006-
.
I meant any year with "-" symbol at the end
Products.period like '%-'
will match anything where period
ends with the string -
.
Upvotes: 4