Cycymomo
5/27/2014 - 11:28 AM

gistfile1.js

console.highlight = function(text, sample) {
  var escapedSample = sample.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  var reSample = new RegExp(escapedSample, 'g');
  var args = [''];
  var highlightedText = text.replace(reSample, function(match) {
    args.push('background-color: #ffc', 'background-color: none');
    return '%c' + match + '%c';
  });
  args[0] = highlightedText;
  console.log.apply(console, args);
};