如何使用XPath仅从字符串中获取数字 [英] How to get only numbers from string with XPath

查看:32
本文介绍了如何使用XPath仅从字符串中获取数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数字的字符串.仅使用 XPath 是否可行,我只能从中获取数字?

I have a string which contains numbers. Is it feasible only with XPath that I get only numbers from it?

例如:myString="abcd12ef34gh567",结果:1234567

For example: myString="abcd12ef34gh567", result: 1234567

推荐答案

使用:

translate(., translate(.,'0123456789',''), '')

这就是所谓的双重翻译"方法,首先由@Michael Kay 提出,可以在 XPath 1.0 和 XPath 2.0 中使用.

This is the so called "double-translate" method, first proposed by @Michael Kay and can be used both in XPath 1.0 and in XPath 2.0.

当然,在 XPath 2.0 中使用 RegeX 通常会更高效:

replace('abc123def590xyz', '[^\d]', '')

这篇关于如何使用XPath仅从字符串中获取数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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