skip to Main Content

I am having a set of strings like this in a report field:

cpe:/o:redhat:enterprise_linux:7

cpe:/o:centos:centos:7

I need to extract the words after the second last colon ":"

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

There are some regular expressions in like

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

Please help with your suggestions. Thanks

2

Answers


  1. You may use the following regex pattern:

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

    Updated code:

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

    Here is a regex demo showing that the pattern is working against your sample text.

    Login or Signup to reply.
  2. Added " " and a Capturing Group ( ) to the Answer by Tim Biegeleisen to ensure that the REGEXP_EXTRACT Calculated Field captures the required values:

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

    Editable Google Data Studio Report and a GIF to elaborate:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search