是否HtmlAgilityPack在其XPATH选择使用正则表达式的能力? [英] Does HtmlAgilityPack have the ability to use regular expressions in its XPATH selector?
问题描述
我希望能够创建节点的集合,其中的文字用字,然后数字开始。例如,给出以下内容:
< P> FINDTHIS 1 LT; / P>
< P> FINDTHIS SOMETEXT< / P>
将p为H.; FINDTHIS 2'; / P>
我希望能够创建由两个段落节点的集合:FINDTHIS 1和FINDTHIS 2
一种可能的方法是创建一个XPath查询像 // p [开始-与('FINDTHIS')]
,然后使用正则表达式来确定下一个字符是否是一个数字。如果我想获得返回的上述标准匹配的列表,我可以创建一个正则表达式对象和测试集合中的每个成员的文本。
有没有使用HtmlAgilityPack?
没有的 HTML敏捷性包目前不支持这一点。它支持版本的XPath查询1,不支持正则表达式。
这是说,你必须做你建议并选择使用XPath表达式到要使用正则表达式的点,然后使用的 其中,
扩展方法筛选出合适的基于一个 正则表达式节点code>
实例。
I would like to be able to create a collection of nodes where the text starts with a word and then a number. For example, given the following:
<p>FINDTHIS 1</p>
<p>FINDTHIS SOMETEXT</p>
<p>FINDTHIS 2</p>
I would like to be able to create a collection consisting of two paragraph nodes: FINDTHIS 1 and FINDTHIS 2.
One possible approach would be to create an xpath query like //p[starts-with(., 'FINDTHIS ')]
and then use a regular expression to determine whether or not the next character is a number. If I wanted to obtain a list of matches that returned the above criteria, I could create a regular expression object and test the text for each member in the collection.
Is there a way to utilize a regular expression directly within the selector using HtmlAgilityPack?
No, the HTML Agility Pack does not currently support this. It supports XPath version 1 queries, which does not support regular expressions.
That said, you'll have to do as you recommended and select using the XPath expression up to the point where you want to use a regular expression, and then use the Where
extension method to filter out the appropriate nodes based on an RegEx
instance.
这篇关于是否HtmlAgilityPack在其XPATH选择使用正则表达式的能力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!