Hi,
I've read the documentation about the
GAQL grammar, however I cannot find an easy way to replicate AdWords' CONTAINS behavior in some cases.
I'm mostly interested in returning a list of campaigns that contain a specific substring. This substring should never be interpreted, even it has special characters.
For instance, let's assume we have an account with these two campaigns:
- TestCampaignProduct1Search
- [test][campaign][product2][search]
In Google AdWords I could write:
- CampaignName CONTAINS "CampaignProduct1" --> returns TestCampaignProduct1Search (ok)
- CampaignName CONTAINS "[campaign][product2]" --> returns [test][campaign][product2][search] (ok)
that worked because the squared brackets weren't interpreted as special characters.
In Google Ads:
-
campaign.name LIKE "%CampaignProduct1%" --> returns TestCampaignProduct1Search (ok)
-
campaign.name LIKE "%[campaign][product2]%" --> [test][campaign][product2][search] is
not matched (not ok but expected)
as pointed out in the documentation, if I want to match a square bracket character it needs to be surrounded by square brackets:
-
campaign.name LIKE "%[[]campaign[]][[]product2[]]%" --> returns [test][campaign][product2][search] (ok but "complex", especially if the Filter is exposed to the users of my application)
using square brackets works but it adds a complexity that I would rather not have.
Isn't there an easier way to execute a search without having special characters interpreted?
I read that REGEXP_MATCH uses re2 and in the
re2 documentation I found the "\Q...\E" escape sequence that matches "literal text ... even if ... has punctuation" but that doesn't seem to be supported by the API as I get an error.
Example:
campaign.name REGEXP_MATCH ".*\Q[campaign][product2]\E.*" --> returns
"Request with ID "0dW9nXNyL8980lNmJJYHVQ" failed with status "INVALID_ARGUMENT" and includes the following errors: Error with message "Error in WHERE clause: invalid value ".*\.""
How come this is invalid even though \Q...\E is listed as a valid escape operator?
Is there a better solution to emulate the old "CONTAINS" behavior?
Cheers