REGEXP_MATCH with space does not match

436 views
Skip to first unread message

francis....@gmail.com

unread,
Apr 25, 2022, 2:21:42 PM4/25/22
to Google Ads API and AdWords API Forum
Hi there, 

I have a very simple query where I need to match a campaign name with a regular expression:

SELECT ad_group_ad.ad.call_ad.description1, campaign.name, metrics.active_view_impressions, metrics.all_conversions
FROM ad_group_ad
WHERE metrics.impressions > 0
AND campaign.name REGEXP_MATCH '(?i).*Google Ads.*'
AND segments.date >= '2022-03-01'
AND segments.date <= '2022-03-31'

I have numerous campaigns with a name containing "Google Ads", I see them if I remove the filter or if I filter on "Google" or "Ads". 

What could be the problem?

Thank you, Francis.

I'm using the new Google Ads API.

Google Ads API Forum Advisor

unread,
Apr 26, 2022, 11:57:39 AM4/26/22
to francis....@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads API support team.

With regards to your concern, please follow the Google Ads Query Language Grammar guide as the single source of truth for GAQL grammar. I would suggest using "WHERE campaign.name LIKE '%Google%Ads%'" as the filter condition. Please try out our Interactive Google Ads Query Builder tool which can help your build up GAQL query. Let me know if you have any question.

Thanks,
Google Logo
Nirmita
Google Ads API Team
 


ref:_00D1U1174p._5004Q2aNQEj:ref

francis....@gmail.com

unread,
Apr 26, 2022, 8:43:02 PM4/26/22
to Google Ads API and AdWords API Forum
Hi Nirmita,

thank you for pointing me out to the Grammar Guide, but I already red it thorougly and could not find a precise reference on how to escape caracters in regular expressions. It says the regular expression uses the re2 syntax, but I found out thru trial and error that many caracters need to be escaped as defined for the LIKE operator:

To match a literal [, ], %, or _ using the LIKE operator, surround the character in square brackets.

I tried the Google Ads Query Builder, but it does not seem to fully check regular expressions. On many occasions the query validator validated queries but at execution time the regular expression was invalid.

As to why I cannot use the LIKE operator, it's because I want to partial match many substrings, for example I'm trying to do the equivalent of:

WHERE campaign.name LIKE '%Google Ads%'" OR  campaign.name LIKE '%Google Analytics%'"

but the OR is not valid as per the grammar guide. So my workaround is to use a regular expression with an Alternative ( "|" ):

WHERE campaign.name REGEXP_MATCH ".*Google Ads.*|.*Google Analytics.*''

It works fine if there is no space in the terms I'm looking for, but if there's a space I get the error "Request contains an invalid argument." at runtime.

So my question is, what is the official way in REGEXP_MATCH to match a literal " " (space), so I can make that kind of query work ?  =>  ".*Google Ads.*|.*Google Analytics.*''

Thanks for you help, Francis

Google Ads API Forum Advisor

unread,
Apr 27, 2022, 11:51:58 PM4/27/22
to francis....@gmail.com, adwor...@googlegroups.com
Hi Francis,

Thank you for getting back to us.

So that we can try on our end and help you to resolve this issue, could you please provide your customer ID?

You can provide it via Reply privately to author option. If this option is not available, then send it instead on this email address googleadsa...@google.com.

Regards,
Google Logo
Carmela
Google Ads API Team
 


ref:_00D1U1174p._5004Q2aNQEj:ref

Google Ads API Forum Advisor

unread,
Apr 28, 2022, 12:11:30 AM4/28/22
to francis....@gmail.com, adwor...@googlegroups.com
Hi Francis,

This is an addition to my previous email.

So we can also try this out on our end, and possibly raise this to the rest of our team, could you also share your complete request and response logs, as well as the login-customer-id you use in your report requests?
Reply all
Reply to author
Forward
0 new messages