replace
val.replace(/(\s*\w+=['"]\$\{\w+\}['"])|(\$\{\w+\})/g, "");
with
val.replace(/(\S*\w+=['"]\{\{\w+\}\}['"])|(\{\{\w+\}\})/g, "");