我可以在一个XPath EX pression使用正则表达式? [英] Can I use a Regex in an XPath expression?

查看:160
本文介绍了我可以在一个XPath EX pression使用正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于 // 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.

但是,您有以下选项

  • Use an XPath 1.0 expression (note the starts-with() and translate() functions) like this:

.//div
   [starts-with(@id, 'foo') 
  and 
   'foo' = translate(@id, '0123456789', '')
  and
   string-length(@id) > 3   
   ]

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