Skip to content

Instantly share code, notes, and snippets.

View jphase's full-sized avatar

Jeff Hays jphase

View GitHub Profile
@jphase
jphase / regexMatch.js
Last active January 28, 2016 22:17
jQuery regex search element text/contents and return matches based on child element containing regex
// Escape all RegEx reserved characters from string
function escRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
// Return matched elements based on regex contents
function highlight(regex, element, child) {
// Create a regex based on the match string
var regex = new RegExp(escRegExp(regex), 'gim');
// Generate results based on regex matches within match_parent