首页 > 解决方案 > How to remove Unicode characters in Snowflake?

问题描述

I am trying to clean data in snowflake table and I see a lot of unicode characters like \U0028. I wrote the following, but not sure how to remove the Unicode.

Select
REGEXP_REPLACE(
           REGEXP_REPLACE(
               REGEXP_REPLACE(lower('MON \U0028 POP STORE'),
                              '[/-_.,&#\'"?~;/+|:|/|]'),
               '( co|inc|pllc|llc|ltd|plc|corp|pc|corporation|incorporated)$'),
           '\\s+',
           ' ') ;

Is the regex possible or I need to use REPLACE(data, '\\u0028', '\\u0306'). Any help would be appreciated.

My data looks like:

VITAMIN \U0026 SUPPLEMENTS STORE

标签: regexsnowflake-cloud-data-platform

解决方案


根据这些实体在现实生活中的情况,有两种可能的解决方案。

如果这些是 char hex 实体并且\u0026实际上是在控制台&中显示的 char,则\u0026您可能不需要采取任何操作,因为它是可以的。

如果这些是您想从可能使用的文本中删除的文字子字符串

REGEXP_REPLACE( input, '\\s*\\\\U\\d{4}', '' )

请参阅此正则表达式演示正则表达式图

在此处输入图像描述

细节

  • \s*- 0+ 个空格
  • \\- 反斜杠
  • U- 一个U字符
  • \d{4}- 四位数。

请注意,在字符串文字内部,每个反斜杠必须像\在字符串中使用的那样进行两次转义,以形成字符串转义序列,如\n(换行符)、\t(制表符)等。请参阅转义字符和警告


推荐阅读