0
votes

I've been trying to use REGEXP_MATCH to create a custom field in Google Data Studio but it's not working as expected.

Example of the data I'm using it on (this is how the data is formatted in the tags_name field:

{construction,po-johnson,po-james}

{construction,po-sandy,po-occonor}

The objective is to check if a certain name exists, then create a new label.

Here's the code I'm trying (tags_name is the field name where the original text string exists):

CASE
  WHEN REGEXP_MATCH(tags_name, ".*(johnson?).*") THEN "Marc Johnson"
  WHEN REGEXP_MATCH(tags_name, ".*(occonor?).*") THEN "Sam Occonor"
  ELSE "undefined"
END

Is this happening due to the presence of the curly brackets/commas/hyphens?

1
In what way is it 'not working as expected'? Are you getting "undefined" with tags_name that should be recognized? Are you getting an error message?colourCoder
i'm getting only undefinedjohann_s
Try "(?s).*(johnson?).*" and "(?s).*(occonor?).*"Wiktor Stribiżew
It would be good to check whether your tags_name parameter is fed properly. You can check it by replacing the result in the ELSE close. Instead of ELSE "undefined", try ELSE CONCAT("The tags_name is: ", tags_name).colourCoder
@WiktorStribiżew tried this one but still not picking up any valuejohann_s

1 Answers

0
votes

I've tried to reproduce the error in Google Data Studio based on your problem statement. Everything worked exactly as expected though.

I've entered your input (and a few other expressions for confirmation) in the tags_name field and placed your REGEXP_MATCH function into another field:

Screenshot of Data Studio Report with a regex detail

Here is the result:

Data Studio report table with tags_name column and result column

Is this the result you expected?

Is there still an issue? If so, you could edit your question and add corresponding screenshots.