【问题标题】:REGEXP_SUBSTR in TeradataTeradata 中的 REGEXP_SUBSTR
【发布时间】:2018-09-12 03:10:18
【问题描述】:

我在 XXX/XXXX/XXXX/XYYUX/YYY 之类的列中有数据。我试图仅提取本示例中为“XY”的列中第三个反斜杠(/)之后的前两位数字。你能帮忙吗? 谢谢!

【问题讨论】:

  • (?:[^\/]+\/){6}(\w{2})..这有效..谢谢!
  • 我仍在尝试处理语法。我尝试了 REGEXP_SUBSTR (Column_Name,?:[^\/]+\/){6}(\w{2})AS TEST 和它没用..你能帮忙吗?
  • 有一个未记录的 REGEXP_SUBSTR 变体,它允许指定返回哪个捕获组:RegExp_Substr_gpl(s, '(.*?/){3}(..)',1,1,'i',2),但是 TD14 有一些不同,那么RegExp_Substr_gpl(s, '(?:.*?/){3}(..)',1,1,'i',1) 可能会起作用。

标签: regex teradata regexp-substr


【解决方案1】:

试试这个:

    REGEXP_SUBSTR('XXX/XXXX/XXXX/XYYUX/YYY','^([^/]*/){3}\K..',1,1,'i')


'^' start of string
'([^/]*/){3}' looks for 0 or more non-slashes followed by a slash, 3 times
'\K' match reset operator drops the part of the string that has been matched up to this point
'..' grabs the next two characters in the string

【讨论】:

  • 不知道Teradata支持\K,不错。
  • 嗨,如果我需要启动一个新线程,请先道歉......我遇到了一个非常相似的问题 - 我在 word1/word2///word3/word4/word5 列中有数据,长度为每个单词和总长度都不同。我正在尝试提取第 n 个和第 n+1 个 / 之间的整个单词,你能帮忙吗?谢谢!
【解决方案2】:

尝试使用 -STRTOK('/88/209/89/132]', '/]', 3)

返回第 3 个八位字节,'89'

【讨论】:

    猜你喜欢
    • 2021-12-06
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 2022-01-17
    • 2016-07-11
    • 2018-03-11
    • 2018-10-13
    相关资源
    最近更新 更多