悬空元字符 * sparksql [英] Dangling metacharacter * sparksql

查看:56
本文介绍了悬空元字符 * sparksql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的正则表达式在 Hive 中有效,但在 Spark 中无效.

Below regex works in Hive but not in Spark.

它抛出一个错误dangling metacharacter * at index 3:

It throws an error dangling metacharacter * at index 3:

select regexp_extract('a|b||c','^(\\|*(?:(?!\\|\\|\\w(?!\\|\\|)).)*)');

我也尝试用 \\* 转义 * 但它仍然抛出 dangling metacharacter * at index 3.

I also tried escaping * with \\* but still it throws dangling metacharacter * at index 3.

推荐答案

可以使用

regexp_replace(col, '^(.*)[|]{2}.*$', '$1')

查看正则表达式演示.

正则表达式详情:

  • ^ - 字符串的开始
  • (.*) - 捕获组 1(此组值通过 $1 替换反向引用 在替换模式中):除换行符以外的任何零个或多个字符,尽可能多(行的其余部分)
  • [|]{2} - 双管道(|| 字符串)
  • .* - 其余部分
  • $ - 字符串结束.
  • ^ - start of string
  • (.*) - Capturing group 1 (this group value is referred to with $1 replacement backreference in the replacement pattern): any zero or more chars other than line break chars, as many as possible (the rest of the line)
  • [|]{2} - double pipe (|| string)
  • .* - the rest of the line
  • $ - end of string.

这篇关于悬空元字符 * sparksql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆