Jquery extract text with regular expression on complete visible text of web page

☆樱花仙子☆ 提交于 2019-12-06 02:30:02

问题


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

But I need something different:

  1. The regular expression should search in the whole visible text of the web page.
  2. 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?


回答1:


This should get you an Array of all matches.

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

jsFiddle.



来源:https://stackoverflow.com/questions/6107917/jquery-extract-text-with-regular-expression-on-complete-visible-text-of-web-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!