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

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

问题描述

类似于 .//div[@id='food+] 的东西,用于使用 id='foo123' 捕获 div 标签.

我正在使用 .NET,如果这很重要.

解决方案

正如其他答案所指出的,XPath 1.0 不支持正则表达式.

尽管如此,您还有以下选择:

<前>.//div[开始(@id,'foo')和'foo' = translate(@id, '0123456789', '')和字符串长度(@id)> 3]

Something like .//div[@id='food+] to capture div tags with id='foo123'.

I'm using .NET, if that matters.

解决方案

As other answers have noted, XPath 1.0 does not support regular expressions.

Nonetheless, you have the following options:

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

这篇关于我可以在 XPath 表达式中使用正则表达式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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