首页 > 其他 > 详细

hive中 regexp_replace的用法,替换特殊字符问题

时间:2018-11-07 20:34:27      阅读:1064      评论:0      收藏:0      [点我收藏+]

数据仓库中有的字段不合格,有特殊字符,比如换行符。

poi_name
\n19013
\n12013

怎么把换行符替换掉呢?

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-StringOperators

regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT)

Returns the string resulting from replacing all substrings in INITIAL_STRING that match the java regular expression syntax defined in PATTERN with instances of REPLACEMENT. For example, regexp_replace("foobar", "oo|ar", "") returns ‘fb.‘ Note that some care is necessary in using predefined character classes: using ‘\s‘ as the second argument will match the letter s; ‘\s‘ is necessary to match whitespace, etc.

官网说用两个反斜杠代替一个,即一个反斜杠用来转义。

实践了一下,不行,得4个

````
select regexp_replace(poi_name,‘\\n‘,‘‘)

poi_name
19013
12013
```

hive中 regexp_replace的用法,替换特殊字符问题

原文:https://www.cnblogs.com/woshimrf/p/hive-string-regexp-replace-usage.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!