如何在jsoup中选择与某个正则表达式匹配的TextNode [英] How to select TextNodes matching a certain regex in jsoup

查看:231
本文介绍了如何在jsoup中选择与某个正则表达式匹配的TextNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有HTML,想要找到与某个正则表达式匹配的TextNode.我在API中看到可以找到Elements,但是我需要TextNodes.

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.

推荐答案

来自官方文档:

  • :matches(regex)

  • :matches(regex)

文本匹配的元素 表达.文本可能会出现在找到的元素中,或者出现在其中的任何元素中 后裔.

Elements whose text matches the specified regular expression. The text may appear in the found element, or any of its descendants.

示例:
td:matches(\\d+)查找包含数字的表单元格.
div:matches((?i)login)查找包含文本,大小写的div 麻木不仁.

Examples:
td:matches(\\d+) finds table cells containing digits.
div:matches((?i)login) finds divs containing the text, case insensitively.

:containsOwn(text)

: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.

示例:
p:containsOwn(jsoup)找到p 具有自己的文本"jsoup"的元素.

Example:
p:containsOwn(jsoup) finds p elements with own text "jsoup".

:matchesOwn(regex)

:matchesOwn(regex)

其自身的文本与指定内容匹配的元素 正则表达式.文本必须出现在找到的元素中,而不是任何 它的后代.

Elements whose own text matches the specified regular expression. The text must appear in the found element, not any of its descendants.

示例:
td:matchesOwn(\\d+)直接查找表单元格 包含数字.
div:matchesOwn((?i)login)查找包含以下内容的div 文字,不区分大小写.

Examples:
td:matchesOwn(\\d+) finds table cells directly containing digits.
div:matchesOwn((?i)login) finds divs containing the text, case insensitively.

这篇关于如何在jsoup中选择与某个正则表达式匹配的TextNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆