gpt4 book ai didi

android - 在android中使用sqlite的正则表达式

转载 作者:搜寻专家 更新时间:2023-11-01 08:01:22 24 4
gpt4 key购买 nike

我在使用正则表达式时遇到困难,我有一个产品表,其中一个字段是一个句点。我想按用户在我的应用程序中输入的时间段过滤记录。例如,期间可能是 2006-2012 或只是 2006-

我想过滤所有只包含模式 2006- 的记录

我尝试了很多例子,但不幸的是没有一个能正常工作

这是我的代码

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不适用于正则表达式。

要使用正则表达式匹配,请使用 REGEXP 运算符。请注意,默认情况下 REGEXP operator is not implemented ,即使语法支持它。

更简单的匹配需求也可以考虑GLOB .

I want to filter all the records that contain only the pattern 2006-

你不需要正则表达式。

Products.period like '2006-%'

将匹配 period 以字符串 2006- 开头的任何内容。


I meant any year with "-" symbol at the end

Products.period like '%-'

将匹配任何period以字符串-结尾的内容。

关于android - 在android中使用sqlite的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20907914/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com