我可以在一个XPath EX pression使用正则表达式? [英] Can I use a Regex in an XPath expression?
问题描述
类似于 // DIV [@ ID ='富\ D +]
来捕捉div标签与 ID ='foo123'
。
Something like .//div[@id='foo\d+]
to capture div tags with id='foo123'
.
我使用.NET,如果该事项。
I'm using .NET, if that matters.
推荐答案
至于其他的答案已经注意到, 的XPath 1.0 一>不支持正EX pressions
As other answers have noted, XPath 1.0 does not support regular expressions.
但是,您有以下选项
- 使用XPath 1.0 EX pression (注意<一href="http://www.w3.org/TR/xpath#function-starts-with"><$c$c>starts-with()$c$c>和
翻译()
一>函数)是这样的:
- Use an XPath 1.0 expression (note the
starts-with()
andtranslate()
functions) like this:
.//div
[starts-with(@id, 'foo')
and
'foo' = translate(@id, '0123456789', '')
and
string-length(@id) > 3
]
-
使用<一个href="http://www.$c$cplex.com/MVPXML/Wiki/View.aspx?title=EXSLT.NET&referringTitle=Home">EXSLT.NET - 有一种方法来 ,而不必使用其功能直接在XPath的EX pressions使用XSLT 。该EXSLT扩展功能,允许使用正则表达式-ES是:<一href="http://exslt.org/regexp/functions/match/index.html"><$c$c>regexp:match()$c$c>, <一href="http://exslt.org/regexp/functions/replace/index.html"><$c$c>regexp:replace()$c$c>和<一href="http://exslt.org/regexp/functions/test/index.html"><$c$c>regexp:test()$c$c>
Use EXSLT.NET -- there is a way to use its functions directly in XPath expressions without having to use XSLT. The EXSLT extension functions that allow RegEx-es to be used are:
regexp:match()
,regexp:replace()
andregexp:test()
使用 的XPath 2.0 / < A HREF =http://www.w3.org/TR/xslt20/> XSLT 2.0 和它的 内置定期EX pressions 支持(功能的 匹配() , 替换() 和 标记化() )
Use XPath 2.0/XSLT 2.0 and its inbuilt support for regular expressions (the functions matches(), replace() and tokenize())
这篇关于我可以在一个XPath EX pression使用正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!