Jquery extracts regular expression text to the full visible text of a web page

I am aware of the jQuery regex plugin from James Padolsey: http://james.padolsey.com/javascript/regex-selector-for-jquery/

But I need something else:

  • The regular expression should look in all visible text of the web page.
  • I want to get the text myself, and not the element containing it.

The following will meet requirement 1, but not 2:

$('*').filter(function() { return this.text().match(/\d\d\d/); }); 

Any idea how I can do this with good performance?

+4
source share
1 answer

That should give you an Array all matches.

 var text = $('body').text().match(/\d{3}/g); 

jsFiddle .

+9
source

All Articles