使用android系统sqlite的普通前pression [英] Regular expression using sqlite in android
问题描述
我有与正则表达式困难,我有一个表产品领域它单曲之一,这是一个周期。
我想通过一段时间的用户在我的应用程序中输入筛选记录。
例如时期可能是2006-2012或只是2006 -
我要过滤所有包含只有2006-2007模式记录
我试过很多例子,但遗憾的是没有正常工作
这是我的code
光标C = rDB.rawQuery(选择标题,从产品,UserProducts那里UserProducts.product_ code = Prodcuts.product_ code和USER_EMAIL =?和产品价格.period LIKE'%[0-9] +%'组由Products.title ASC UserSeries.product_ code令,新的String [] {电子邮件});
而(c.moveToNext())
{
//保存记录
}
Products.period LIKE'%[0-9] +%
LIKE
不用正则表达式工作。
要使用常规的前pression匹配,使用 REGEXP
运营商。请注意,默认情况下, REGEXP
运营商未实现时,即使该语法支持它
有关简单的匹配需要你也可以考虑 GLOB
。
我要过滤所有包含只有2006年的模式记录 -
块引用>您不必为一个普通的前pression。
Products.period像'2006-%
其中,
周期
以开头会匹配任何2006 -
我的意思是任何一年以 - 号在结束
块引用>Products.period LIKE'% - '
-
将匹配任何内容,其中
周期
与字符串结束
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 }
解决方案Products.period like '%[0-9]+%'
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
.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 string2006-
.
I meant any year with "-" symbol at the end
Products.period like '%-'
will match anything where
period
ends with the string-
.这篇关于使用android系统sqlite的普通前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!