Skip to content

Instantly share code, notes, and snippets.

@jney
Created December 19, 2010 01:14
Show Gist options
  • Save jney/747021 to your computer and use it in GitHub Desktop.
Save jney/747021 to your computer and use it in GitHub Desktop.
if (typeof $().highlightRegex === "function") {
!RegExp.escape && (RegExp.escape = function(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
});
$('#rech').keypress(function () {
$('#NewsHome').highlightRegex();
var txt = $(this).val();
if (txt.length > 2) {
try {
var regex = new RegExp(RegExp.escape(txt), 'ig');
$('#NewsHome').highlightRegex(regex);
} catch (e) {}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment