Data Studio
3.3K members online now
3.3K members online now
Ask questions about Data Studio
Guide Me
star_border
Reply

Regex formulas for new dimensions not working ... why?

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi everyone,

 

I'm using a Google Analytics data connection & want to make a new dimension that is the Landing page minus any query parameters.

 

But it's not working. Here's my formula:

REGEXP_REPLACE(Landing Page,'\?.*','')

 

This works totally fine when I use the companion formula in google sheets ... REGEXREPLACE(C16,"\?.*","") ... but it doesn't work here. Why?

Regex formulas for new dimensions not working ... why?

[ Edited ]
Explorer ✭ ✭ ✭
# 2
Explorer ✭ ✭ ✭

Maybe try REGEXP_REPLACE(Landingpage, ".*\?.*","")

The REGEX in Data Studio seems a bit more picky than Sheets for some reason. 

 

Regex formulas for new dimensions not working ... why?

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Hi @Ad A,

 

Unfortunately that regex won't work for my purposes because the first .* will throw off the results

 

Regex formulas for new dimensions not working ... why?

Explorer ✭ ✭ ✭
# 4
Explorer ✭ ✭ ✭

I just realized that the code I gave you would replace every URL with a query parameter with nothing.

You may need to use a LEFT formula or a REGEXP_EXTRACT formula to save the URL path instead of replacing the query path. 

I don't know the formulas off the top of my head, but you can do a search for extracting different URL components with REGEX formulas and maybe give some of those a shot. 

Regex formulas for new dimensions not working ... why?

[ Edited ]
Explorer ✭ ✭ ✭
# 5
Explorer ✭ ✭ ✭

Ignore my last reply, try this instead REGEXP_REPLACE(Landing Page, '[\?.*]',"")

I tested that one and it worked for me

 

Regex formulas for new dimensions not working ... why?

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Hi @Ad A,

 

I appreciate your dedication, but that formula just replaces the ?. It doesn't remove the entire query string.

 

What I am trying to do is for example take Landing Page value /home/?queryname=queryvalue & output just /home/

 

With your formula, /home/?queryname=queryvalue becomes /home/queryname=queryvalue

 

Regex formulas for new dimensions not working ... why?

[ Edited ]
Explorer ✭ ✭ ✭
# 7
Explorer ✭ ✭ ✭

That's odd, did you do '[?.*]' or just '?.' because the '[?.*]' worked for me. I actually needed to clean up some URLs for a report I'm working on so I needed to figure this out too.

I will send over a screenshot later just in case I missed something here.