Use REGEXP_MATCH to find Square Brackets and Quotes

79 views
Skip to first unread message

Martin Manchev

unread,
Apr 18, 2022, 8:32:04 AM4/18/22
to Google Ads Scripts Forum
Hello, 

I'm experimenting with the new scripts experience and I'm trying(for now with no luck)
to filter out some incorrectly typed negative keywords from our campaigns. 

I'm searching for negative keywords that have ONLY an opening or closing square bracket(but not both at the same time) or just 1 quote.

for example:
"tets 1 - I need this
"test 2" - skip this one
[test 3 -  need this as well
[test 4] - regex should skip this one

I'm thinking of something like:
var negativeKeywordSelector = campaign.negativeKeywords().withCondition("campaign_criterion.keyword.text REGEXP_MATCH '\[.*|.*\]'").get();

but I have some troubles with escaping the special characters ],[ and ".
Even If I try with \\ in front of the special characters, the selector still doesn't work properly. 
I came across this conversation, but it didn't work in my situation 
https://groups.google.com/g/adwords-scripts/c/n96t2N3G-PY/m/efYDoYG2AQAJ


Any help would be much appreciated. Thank you!

Google Ads Scripts Forum Advisor

unread,
Apr 20, 2022, 2:21:00 AM4/20/22
to adwords...@googlegroups.com

Hello Martin,

Thank you for reaching out to us.

Can you share to us your CID and script name so our team can further check on this?

Regards,

Google Logo
Mark Kevin
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2a4E9q:ref
Reply all
Reply to author
Forward
0 new messages