【问题标题】:Incorrect regex_replace while decoding to Hebrew解码为希伯来语时不正确的 regex_replace
【发布时间】:2021-06-02 13:58:28
【问题描述】:

下面的代码不起作用,因为我的 regex_replace 没有按应有的方式处理空格。帮助! 创建临时函数 解码(字串)AS(( 选择 如果 (STARTS_WITH(word, ''), safe.code_points_to_STRING(ARRAY( 选择 CAST(值作为 int64) 从 UNNEST(SPLIT(REPLACE(REGEXP_REPLACE(word, '[^a-zA-Z0-9]', ''), '', '0'),';')) 值 在哪里 非值 = '' )), 单词) )); 和 数据作为( 选择 'שבחים לסוקולובסקי, האריס: ידענו שתהיה מלחמה'txt) 选择 ( 选择 STRING_AGG(解码(字),'') 从 UNNEST(SPLIT(txt, ' ')) word ) AS 希伯来语_txt 从 数据;

预期结果:שבחים לסוקולובסקי,האריס:ידענו שתהיה מלחמה

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    考虑下面

    create temp function decode(word string) as ((
      select if(starts_with(word, '&#x'), 
        safe.code_points_to_string(array(
          select ifnull(safe_cast(value as int64), ascii(value))
          from unnest(split(replace(word, '&#', '0'),';')) value
          where not value = ''
        )), 
        word)
    ));
    select (
        select string_agg(decode(word), ' ')
        from unnest(split(txt, ' ')) word
      ) as Hebrew_txt
    from data               
    

    如果应用于您问题中的样本数据 - 输出是

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      • 2015-07-03
      • 1970-01-01
      相关资源
      最近更新 更多