Bug in regex causes irrelevant campaigns to be returned

36 views
Skip to first unread message

Luuk

unread,
Mar 29, 2022, 11:54:59 AM3/29/22
to Google Ads Scripts Forum
Hi,

For one of our clients we have a script that gets all ad groups and checks if they should be enabled or paused, depending on a value in a specific feed. As part of this script we are getting all ad groups with some conditions.

In the actual script we're filtering out ad groups that belong to campaigns that have (B) or "remarketing" in their name. However, for the purpose of debugging I have reversed the regex to only get ad groups that actually do include (B) as this will make it easier to see that the regex fails.

CID: 472-622-8957
Script name: Temporary

I have set up the script now so that it logs an array of all campaign names. As you will see when running the script this also logs campaign names that don't include (B)

For some reason the regexp_match seems to fail, but I haven't been able to find anything with it myself. Looking at the output, I see all campaigns being logged contain a B so perhaps something is going wrong escaping the ( and ) that are around the B in the campaign name?

I know I could try using contains but this regexp_match should work as well, right?


Best,
Luuk


Google Ads Scripts Forum Advisor

unread,
Mar 30, 2022, 6:26:00 AM3/30/22
to adwords...@googlegroups.com

Hello Luuk,

Thank you for reaching out to us. I’m James from the Google Ads Script support team.

Upon checking with the given script, I noticed that you incorrectly set up the regex in your condition which is the main reason why you were unable to retrieve those campaigns that have ‘(B)’ in their names. Having said that, can you please try the following condition below and let me know how it goes on your end?

const pausedAndActiveAdGroups = AdsApp.adGroups()
.withCondition("campaign.name REGEXP_MATCH '.*\[(]B\[)].*'")
.get();

On the other hand, I confirm that REGEXP_MATCH should also work as well according to our documentation.

Let me know if you have any questions.

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2YsZTG:ref

Luuk

unread,
Mar 30, 2022, 6:37:26 AM3/30/22
to Google Ads Scripts Forum
Hi,

Thanks I will try that out later today. So we have to escape the ( both with a backslash and square brackets? Is there any documentation? I'm only used to escaping with a single or double backslash.

Op woensdag 30 maart 2022 om 12:26:00 UTC+2 schreef adsscripts:

Google Ads Scripts Forum Advisor

unread,
Apr 1, 2022, 3:40:58 AM4/1/22
to adwords...@googlegroups.com

Hello Luuk,

Yes, you need to use backslash followed by bracket if you’re going to interpret a parenthesis () as a character or string. I’m afraid that we don't have any documentation about this. However, I believe that this is how Javascript reads regular expressions. In-addition to that, I found this post within stockoverflow that might help you to get more information about this.

Regards,

Reply all
Reply to author
Forward
0 new messages