Jquery extract text with regular expression on complete visible text of web page
I am aware of the jQuery regex plugin of James Padolsey: http://james.padolsey.com/javascript/regex-s开发者_运维百科elector-for-jquery/
But I need something different:
- The regular expression should search in the whole visible text of the web page.
- I want to get the text itself, not the element containing them.
The following will match requirement 1, but not 2:
$('*').filter(function() {
return this.text().match(/\d\d\d/);
});
Any idea how i can do this with a good performance?
This should get you an Array
of all matches.
var text = $('body').text().match(/\d{3}/g);
jsFiddle.
精彩评论