hive-sql截取汉字、字母和数字等

在查询字段中截取汉字、字母和数字等代码如下:

1、截取数字

select regexp_extract('$%^&&*!(123hello你好,。.,','([0-9]+)',1);
--输出:123
select regexp_replace('$%^&&*!(123hello你好,。.,','[^0-9]','');
--输出:123

 2、截取字母

select regexp_extract('$%^&&*!(123hello你好,。.,','([a-zA-Z]+)',1);
---输出:hello
select regexp_extract('$%^&&*!(123hello你好,。.,','[^a-zA-Z]','');
---输出:hello

  3、截取汉字

select regexp_extract('$%^&&*!(123hello你好,。.,','([\\\u4e00-\\\u9fa5]+)',1);
---输出:你好
select  regexp_replace('$%^&&*!(123hello你好,。.,','[^\\\u4e00-\\\u9fa5]','');
---输出:你好

   4、截取字母、数字或汉字

select regexp_extract('$%^&&*!(123hello你好,。.,','([0-9a-zA-Z\\\u4e00-\\\u9fa5]+)',1);
---输出:123hello你好
select regexp_replace('$%^&&*!(123hello你好,。.,','[^0-9a-zA-Z\\\u4e00-\\\u9fa5]','');
---输出:123hello你好

    原文作者:橘子的博客
    原文地址: https://blog.csdn.net/weixin_42679482/article/details/120712658
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞