-1

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.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

1 Answers1

0

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')
AymDev
  • 6,626
  • 4
  • 29
  • 52
  • which function should I use it in? REGEXP_REPLACE or a different one? this give the error Syntax error: Unexpected ".". in google data studio – Teun de Kort Mar 16 '23 at 13:24
  • @TeundeKort I don't know anything about Google Data Studio but from what I found it seems like this would be the correct function to use: `REGEXP_REPLACE(column, '(.*)(-.*){2}', '\\1')`. Tell me if that works and I'll update my answer. – AymDev Mar 16 '23 at 13:27
  • @TeundeKort great ! You can upvote and accept answers when they solve your problem. I updated my answer with the function call. – AymDev Mar 16 '23 at 13:58