Home » jQuery regex search element text/contents and return matches based on child element containing matched regex string

jQuery regex search element text/contents and return matches based on child element containing matched regex string

Many people have asked me in the #jquery channel on freenode how to find content within elements on a page using regex matching, so I figured I’d write a quick post on one of the ways I’ve done this.

I initially wrote this code for a node app I wrote that uses cheerio to scrape content from sites and return the matched results, but this particular version is repurposed to a standard jQuery approach:

And here’s some test HTML markup that goes along with it:

And just in case you need a working example of this highlighting all purdy and pink, here’s a jsfiddle for ya:  http://jsfiddle.net/jphase/QmgDL/

Leave a Reply

Your email address will not be published. Required fields are marked *