Hive 正则表达式使用 与 匹配中文
2016-09-09 10:51
513 查看
1.regexp
语法: A REGEXP B操作类型: strings
描述: 功能与RLIKE相同
select count(*) from olap_b_dw_hotelorder_f where create_date_wid not regexp '\\d{8}'
与下面查询的效果是等效的:
select count(*) from olap_b_dw_hotelorder_f where create_date_wid not rlike '\\d{8}';
匹配中文:
self.reg = ‘regexp "[\u4e00-\u9fa5]"’ sql_s = 'select word, searchapp from searchapp_%s where event_week = %s and word %s limit 100000000'%(language,ew_max,self.reg)
**
2.regexp_extract
**语法: regexp_extract(string subject, string pattern, int index)
返回值: string
说明:将字符串subject按照pattern正则表达式的规则拆分,返回index指定的字符。
hive> select regexp_extract('IloveYou','I(.*?)(You)',1) from test1 limit 1;
Total jobs = 1
…
Total MapReduce CPU Time Spent: 7 seconds 340 msec
OK
love
Time taken: 28.067 seconds, Fetched: 1 row(s)
hive> select regexp_extract('IloveYou','I(.*?)(You)',2) from test1 limit 1;
Total jobs = 1
…
OK
You
Time taken: 26.067 seconds, Fetched: 1 row(s)
hive> select regexp_extract('IloveYou','(I)(.*?)(You)',1) from test1 limit 1;
Total jobs = 1
…
OK
I
Time taken: 26.057 seconds, Fetched: 1 row(s)
hive> select regexp_extract('IloveYou','(I)(.*?)(You)',0) from test1 limit 1;
Total jobs = 1
…
OK
IloveYou
Time taken: 28.06 seconds, Fetched: 1 row(s)
hive> select regexp_replace("IloveYou","You","") from test1 limit 1; Total jobs = 1
…
OK
Ilove
Time taken: 26.063 seconds, Fetched: 1 row(s)
hive中的正则可以用,但是有所区别,区别在于原来的‘\’ 转义,这里变成了双斜杠了‘\’
hive中的正则解析函数:regexp_extract; 例如:‘匹配 10.122.248’
select regexp_extract(host,'(^[\\w]+)\\.([\\w]+)\\.([\\w]+)',0) aa from browsewebpagelog where dt like '20140630%';
第一参数:要处理的字段,第二参数需要匹配的正则表达式,第三个参数:0是显示与之匹配的整个字符串,1,是显示第一个括号里面的,2是显示第二个括号里面的字段…
**
3.regexp_replace
**语法: regexp_replace(string A, string B, string C)
返回值: string
说明:将字符串A中的符合java正则表达式B的部分替换为C。注意,在有些情况下要使用转义字符,类似oracle中的regexp_replace函数。
hive> select regexp_replace("IloveYou","You","") from test1 limit 1;
Total jobs = 1
…
OK
Ilove
Time taken: 26.063 seconds, Fetched: 1 row(s)
hive> select regexp_replace("IloveYou","You","lili") from test1 limit 1;
Total jobs = 1
…
OK
Ilovelili
相关文章推荐
- sublimetext 使用正则表达式匹配中文
- 使用Hive的正则表达式匹配数据时为NULL
- Python使用中文正则表达式匹配指定中文字符串的方法示例
- Python如何使用正则表达式匹配中文
- xcode使用正则表达式匹配中文字符
- PHP和javascript中使用正则表达式匹配中文字符串
- Python中使用中文正则表达式匹配指定的中文字符串
- 使用正则表达式匹配中文
- PHP使用正则表达式匹配中文,有部分匹配不出来的解决办法
- 使用“正则表达式”,匹配任意一个字符(中文,英文和标点或特殊字符)
- Visual Studio 中自带的电子邮件的正则表达式匹配中文的问题 与 \w
- 正则表达式匹配中文字符,Ctrl+F的福音!
- Delphi中用正则表达式匹配中文字符
- 转:常用正则表达式大全!(例如:匹配中文、匹配html)
- Regex.Match,使用正则表达式匹配字符串
- SQL Server 2005 中使用正则表达式匹配
- 中文相关正则表达式匹配
- 中文正则匹配,匹配中文,正则表达式
- 使用正则表达式计算字符串中中文字符的个数
- 常用正则表达式大全!(例如:匹配中文、匹配html)