js regex replace multiple words
- by Raghav
I need to replace ${conferance name} with ABC, ${conference day} with Monday in the following sentence.
Could some one help me with the regex.
var text = "<td>${conference name}</td><td>${conference day}</td>"
var list = ["${conferance name}", "${conference day}" ]
for (var j = 1; j < list.length; j++) {
//Extracting the col name
var colName = list[j].split("${");
colName = colName.split("}")[0];
//Replacing the col name
text = text.replace(new RegExp('\\$\\{' + colName + '\\}', 'g'), "ABC");
}
The above code repalces fine if i have ${conference_name}, but it fails when i have a space in between.
The list is a dynamic array. And the Replace statements are also dynamic. I just simulated them as objects here for fitting them in the Regex Statement.
Thanks in Advance.