hive正则表达式

正则匹配

使用regexp进行正则匹配

准备数据

drop table if exists test.test_zw;
CREATE TABLE if not exists test.test_zw(
  stu_id int COMMENT '学生id',
  mobile string comment '手机号'
)
COMMENT '测试表'
STORED as parquet TBLPROPERTIES('parquet.compression'='SNAPPY');
  
  
insert into test.test_zw values
(1,15966668888),
(2,1598888);

查询mobile不是11为数字的数据

select *
from  test.test_zw
where mobile not regexp '\\d{11}'
正则替换

逗号替换为下划线

select regexp_replace('a,b,c',',','_') -- 返回 'a_b_c'

将c替换为空字符串,相当于删除c

select regexp_replace('a,b,c','c','') -- 返回 a,b,

删除b或者c

select regexp_replace('a,b,c','b|c','') -- 返回 a,,
正则截取

提取链接中的sku_id,返回sku_id=1234567,表示一个或者多个数字

select regexp_extract('https://detail.tmall.com/item.htm?sku_id=1234567','sku_id=(\\d+)',0)
-- \\d+表示一个或者多个数字。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值