Skip to content

Instantly share code, notes, and snippets.

@kangax
Created May 27, 2014 11:28
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kangax/d645803cfcb114de1ef3 to your computer and use it in GitHub Desktop.
Save kangax/d645803cfcb114de1ef3 to your computer and use it in GitHub Desktop.
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);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment