Get keyword text without modifiers: [ ], " ", +

24 views
Skip to first unread message

Andreas M.

unread,
Jun 9, 2015, 9:54:30 AM6/9/15
to adwords...@googlegroups.com
Hi,

keyword.getText() returns the keyword string including modifier. There seems to be no easy way to get only the keyword text without the modifier.

e.g.
[shoes] => shoes
"shoes" => shoes
+new +shoes => new shoes

I just wanted to share my best practice for dealing with that topic using a regular expression:

function main() {
   
var keywords = AdWordsApp.keywords()
       
.withCondition('Status=ENABLED')
       
.withLimit(20)
       
.get();
   
while (keywords.hasNext()) {
       
var keyword = keywords.next();
       
Logger.log(keyword.getText() + ' =>');
       
Logger.log(kwTextWithoutModifier(keyword.getText()));
       
Logger.log('\n');
   
}
}

function kwTextWithoutModifier(keywordText) {
   
return keywordText.replace(/(^|\s)\+|^\[|\]$|^\"|\"$/g, "$1");
}

It took me quite a while to figure it out... It should work for modified broads as well.

Please let me know if you know an easier way to deal with this.

Thanks,
Andreas

Reply all
Reply to author
Forward
0 new messages