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

Need help with a regex - include 1 but not 10 in the url

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi dear community,

 

I am sure this is something I will regret asking later... but I can't get my head around it.

 

I have 2 URLs: 

(1) /jobs/finance-and-office-manager/499861?tsid=10

(2) /jobs/finance-and-office-manager/499861?tsid=1

 

In GA I am creating 2 goals with destination URLs

(1) tsid=10

(2) tsid=1     The problem is here, because this 2nd goal is tracking both 1 and 10. 

Sometimes, there are other characters after the tsid=1 so I can't use $.

 

I also tried tsid=[1]{1} and tsid=[^234567890]{1} but no luck.

 

Alex

Marked as Best Answer.
Solution
Accepted by topic author Aleksandra V
June

Need help with a regex - include 1 but not 10 in the url

Explorer ✭ ✭ ☆
# 2
Explorer ✭ ✭ ☆

hi alexandra, 

first, dupplicate your field with URL and give the name URLVALUE

 

Try this : 

CASE 
WHEN REGEXP_MATCH (URLVALUE, "tsid=10") THEN "Goal10"

WHEN REGEXP_MATCH (URLVALUE, "tsid=1") THEN "Goal01"

END 

Need help with a regex - include 1 but not 10 in the url

Participant ✭ ✭ ☆
# 3
Participant ✭ ✭ ☆

Can you restrict it to page=/jobs/finance-and-office-manager/499861?tsid=1? That should exclude 10...

Need help with a regex - include 1 but not 10 in the url

Explorer ✭ ✭ ☆
# 4
Explorer ✭ ✭ ☆

hi Alexandra, i wrote you to fast. 

 

Best way will be to write this formula : 

first, dupplicate your field with URL and give the name URLVALUE

 

Try this formula : 

CASE 
WHEN REGEXP_MATCH (URLVALUE, "tsid=10") THEN "Goal2"

ELSE "Goal1"

END

 

Or you can try this formula too if the previous one is not working : 

CASE 
WHEN REGEXP_MATCH (URLVALUE, ".tsid=10") THEN "Goal2"

ELSE "Goal1"

END

 

Need help with a regex - include 1 but not 10 in the url

Explorer ✭ ✭ ☆
# 5
Explorer ✭ ✭ ☆

Hi @Aleksandra V,

Try: 
Goal 2: tsid=1[^0]{1}   //will match tsid=1 not tsid=10

Goal 1: tsid=10              //will match tsid=10

Thanks,
Ritwik B

Need help with a regex - include 1 but not 10 in the url

[ Edited ]
Participant ✭ ✭ ✭
# 6
Participant ✭ ✭ ✭

Hi everyone,

I will add my version as well.

Goal 1 > regex > tsid=10$|tsid=10&    // it will match tsid=10 or tsid=10&dir=abc but will not match tsid=100 or tsid=104 or tsid=1 or tsid=100&dir=abc

Goal 2 > regex > tsid=1[^0]|tsid=1$|tsid=10[0-9]    // it will match tsid=1 or tsid=13 or tsid=1001 or tsid=1&dir=abc or tsid=114&dir=abc or tsid=104&dir=abc but will not match tsid=10 or tsid=10&dir=abc

I am sure, there's even better solution.

@Aleksandra V  test it out using table filters first and let us know how it works. It really depends on what you'd like to achieve and how complex is the structure of your URLs.

@Ritwik B, I think this regex "tsid=1[^0]{1}" will not match "tsid=1" and this regex "tsid=10" will match "tsid=100" as well. Test it out and let me know if I'm wrong. Smiley Happy

Hope this helps.
Taavi

Need help with a regex - include 1 but not 10 in the url

Explorer ✭ ✭ ☆
# 7
Explorer ✭ ✭ ☆


@Taavi Kalvi - Yes, I missed a lot of use cases here. You are right!!!! Thanks for correcting.

@Aleksandra V - refer to Taavi's solution.