This is something that has been bothering me for a while.
Assume I'm doing this on a line
var result = "Noble warm and pretty darm Caesar.".split(/(\warm)/);
// ["Noble ", "warm", " and pretty ", "darm", " Caesar."]
Would it be possible to extend the split method in order to manipulate regexp catches with a function like replace does on strings?
Pseudo-code:
var result = "Noble warm and pretty darm Caesar.".split(/(\warm)/, function (match) {
return '<span style="color:red;">' + match + '</span>';
});
// ["Noble ", "<span style=\"color:red;\">warm</span>", " and pretty ", "<span style=\"color:red;\">darm</span>", " Caesar."]
.split()and then does more work..split(). Be aware that browsers aren't necessarily consistent with what's returned from.split()when you call it with a regex..split()method and useString.prototype.splitNew?