提取倒数第​​二个冒号后的子字符串

extract substring after second last colon

我在报告字段中有一组这样的字符串:

cpe:/o:redhat:enterprise_linux:7

cpe:/o:centos:centos:7

我需要提取 倒数第二个冒号 ":"

之后
ie.cpe:/o:centos:centos:7 -> should transform as centos:7
  cpe:/o:redhat:enterprise_linux:7 -> should transform as enterprise_linux:7

like里有一些正则表达式

REGEXP_EXTRACT(string,[^\:]+$) -> which gives me the last word after : but not the second last word

请帮忙提出建议。谢谢

您可以使用以下正则表达式模式:

[^:]+:[^:]+$

更新代码:

REGEXP_EXTRACT(string, [^:]+:[^:]+$)

这里有一个 regex demo 显示该模式适用于您的示例文本。

添加了 " " 和捕获组 ( ) to ensure that the REGEXP_EXTRACT Calculated Field 捕获所需的值:

REGEXP_EXTRACT(string, ":([^:]+:[^:]+)$")

Editable Google Data Studio Report 和一张 GIF 来详细说明: