Published in: JavaScript
URL: http://jsfromhell.com/string/highlight
Looks for occurrences of one or more strings on the text and calls a callback to replace it. Created: 2006.01.13
/* ************************************** * String.highlight v1.0 * * Autor: Carlos R. L. Rodrigues * ************************************** */ String.prototype.highlight = function(f, c, i){ var r = this, t = /([(){}|*+?.,^$\[\]\\])/g, i = !i ? "i" : "", rf = function(t, i){ return r.lastIndexOf("<", i) > r.lastIndexOf(">", i) ? t : c(t, p); }; for(var p = -1, l = (f = f instanceof Array ? f : [f]).length; ++p < l;) r = r.replace(new RegExp(f[p].replace(t, "\\\$1"), "gm" + i), rf); return r; }
You need to login to post a comment.
