I have HTML and want to find TextNodes matching a certain regexp. I see in the API that I can find Elements but I need TextNodes.
-
Maybe an empty `contains()` is able to select all text elements? Or just use `:matches(),`, it seems to test text only, see [here](http://jsoup.org/apidocs/org/jsoup/select/Selector.html). You may also see how it can be done with jQuery, since jsoup has jQuery-like methods, e.g. http://stackoverflow.com/questions/298750/how-do-i-select-text-nodes-with-jquery. – CodeManX Apr 27 '14 at 04:51
1 Answers
From the official docs:
:matches(regex)
Elements whose text matches the specified regular expression. The text may appear in the found element, or any of its descendants.
Examples:
td:matches(\\d+)
finds table cells containing digits.
div:matches((?i)login)
finds divs containing the text, case insensitively.
:containsOwn(text)
Elements that directly contain the specified text. The search is case insensitive. The text must appear in the found element, not any of its descendants.
Example:
p:containsOwn(jsoup)
finds p elements with own text "jsoup".
:matchesOwn(regex)
Elements whose own text matches the specified regular expression. The text must appear in the found element, not any of its descendants.
Examples:
td:matchesOwn(\\d+)
finds table cells directly containing digits.
div:matchesOwn((?i)login)
finds divs containing the text, case insensitively.

- 11,159
- 5
- 49
- 70