Search code examples
extractlooker-studiolooker

How to extract text before nth occurrence of special character from the right in lookerstudio


I have an existing field that I want to use to create a new field. I want to keep the text after the second occurrence of "-" from the right. This are some values:

existing value desired output
M-1030-SIS422-1029-XS M-1030-SIS422
JACKSON-0003-28 JACKSON

I want to use a regex expression but I don't know which one.


Solution

  • The following expression should work for you. The desired output is in the 1st capture group, the 2nd capture group is used to match the part you need to remove:

    (.*)(-.*){2}
    

    See Regex101 demo.

    Update: Google Data Studio function call:

    REGEXP_REPLACE(column, '(.*)(-.*){2}', '\\1')