Regular Expression with square bracket "["

58 views
Skip to first unread message

francis....@gmail.com

unread,
Apr 20, 2022, 1:09:32 PM4/20/22
to Google Ads API and AdWords API Forum
Hi there,

I'm trying to use the REGEX_MATCH operator with the Google Ads API to match a string with square brackets. I want to match any string that contains, literally:

"Google [Ads]"

My query where clause is

WHERE campaign.name REGEXP_MATCH ' (?i).*Google \[Ads].* '

Notice I did escape the "[" caracter. It is valid in the query validator, but at runtime I get this error:

Error in WHERE clause: invalid value '(?i).*Google \\.`

Any idea what's wrong with this expression?

Thanks, Francis

P.S. I'm using the .NET SDK. 

Google Ads API Forum Advisor

unread,
Apr 21, 2022, 7:21:22 AM4/21/22
to francis....@gmail.com, adwor...@googlegroups.com
Hi  Francis,

Thank you for raising this concern to the Google Ads API forum. With regard to your concern, could you please try this format below:

WHERE campaign.name REGEXP_MATCH \" (?i).Google [Ads]. \"

I tried this suggested format and it's working on my end so you can try it as well.

Best regards,
Google Logo
Jinky
Google Ads API Team
 


ref:_00D1U1174p._5004Q2a5B6j:ref

francis....@gmail.com

unread,
Apr 21, 2022, 11:15:13 AM4/21/22
to Google Ads API and AdWords API Forum

 Hi Jinky,

the suggested regular expression executes without error, but it does not match the string "Google [Ads]". This is because "[" is a reserved caracter. See the screenshots below from a regex tester using the re2 syntax. 

I would expect the Google Ads API to match the escaped opening square bracket without error.

Thank you, Francis


Regex no escape no match.pngRegex escape match.png

stefano...@webrepublic.ch

unread,
Apr 21, 2022, 12:12:33 PM4/21/22
to Google Ads API and AdWords API Forum
Hi Francis,

Try 

WHERE campaign.name REGEXP_MATCH \" (?i).Google [[]Ads[]]. \"

"To match a literal []%, or _ using the LIKE operator, surround the character in square brackets." source https://developers.google.com/google-ads/api/docs/query/grammar 

Hope this helps

francis....@gmail.com

unread,
Apr 21, 2022, 3:53:08 PM4/21/22
to Google Ads API and AdWords API Forum
It dit work by surrounding in square brackets, thank you!!
Reply all
Reply to author
Forward
0 new messages