the solution is to count the value while
ignoring the keyword insertion pattern.
see below:
},
/*
keyword insertion allows us to auto-inject the triggered keyword into the ad content (kind-of a placeholder).
structure: '{KeyWord: Value}'
the word 'KeyWord' plus the curly brackets are being ignored by the adwords engine so the actual length of such expression equals to the Value length alone
e.g: the length of '{KeyWord: Chocolate}' is 9! (counting only the Chocolate)
*/
countWithoutKeywordInsertion: function(input){
/*
// the value does not include a keyword insertion - return it as is
if(input.indexOf('{') == -1 && input.indexOf('}') == -1)
return input;
*/
var keywordInsertionPattern = /{\s*KeyWord\s*:(.*?)\s*}/ig;
return input.replace(keywordInsertionPattern, '$1').length;