How to exclude special characters in a string using regular expressions in hive

三世轮回 提交于 2019-12-12 04:36:09

问题


I want to exclude periods(.) and braces ((,)).
However, decimal numbers should be left intact

So basically if the input is

Hive supports subqueries only in the FROM clause (through Hive 0.12). The subquery has to be given a name because every table in a FROM clause must have a name. Columns in the subquery select list must have unique names.

The output should be

Hive supports subqueries only in the FROM clause through Hive 0.12 The subquery has to be given a name because every table in a FROM clause must have a name Columns in the subquery select list must have unique names


回答1:


with t as (select 'Hive supports subqueries only in the FROM clause (through Hive 0.12). The subquery has to be given a name because every table in a FROM clause must have a name. Columns in the subquery select list must have unique names.' as mycol)

select  regexp_replace(mycol,'(\\d+\\.\\d+)|[.()]','$1'),'\\((.*?)\\)'
from    t

Hive supports subqueries only in the FROM clause through Hive 0.12 The subquery has to be given a name because every table in a FROM clause must have a name Columns in the subquery select list must have unique names



来源:https://stackoverflow.com/questions/43791225/how-to-exclude-special-characters-in-a-string-using-regular-expressions-in-hive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!