I am trying to replace strings in brackets in some html string. When I use a regular replace, its fast, when I try to create a pattern for global replace, it ends up throwing a stack overflow error. It seems like somewhere along the process path, it converts my single string to an array of characters. Any ideas?
var o = { bob : 'is cool', steve : 'is not' };
for (n in o) {
/*
pattern = new RegExp('\[' + n.toUpperCase() + '\]', 'g');
retString = retString.replace(pattern, o[n].toString());
*/
retString = retString.replace('[' + n.toUpperCase() + ']', o[n].toString());
}