I have this javascript function I found, which replaces all occurences in a string. It works great, but I need it to only work for non-html elements, which simply means any part in the string that isn't between a "<" and ">".
String.prototype.replaceAll = function (strReplace, strWith) {
// See http://stackoverflow.com/a/3561711/556609
var esc = strReplace.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
var reg = new RegExp(esc, 'ig');
return this.replace(reg, strWith);
};
I want this as the "strReplace" string sometimes is found in html, hence messing up the HTML output. Any help is appreciated :)