普通EX pression从字符串中提取号码 [英] Regular expression to extract numbers from a string

查看:125
本文介绍了普通EX pression从字符串中提取号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我建立这种常规的前pression请...

Can somebody help me construct this regular expression please...

由于以下字符串...

Given the following strings...

  • 在四月(123部件少456链轮)
  • 在五月(789部件少012链轮)

我需要一个正规的前pression会从文本中提取的两个数字。月份名称会有所不同。括号,部件少和链轮文本预计不会串之间转换,但是这将是,如果这段文字能变化,以及真正有用的。

I need a regular expression that will extract the two numbers from the text. The month name will vary. The brackets, "widgets less" and "sprockets" text is not expected to change between strings, however it would be really useful if this text was able to be varied as well.

在此先感谢。

推荐答案

如果你肯定知道,目前只有将是2个地方,你必须在你的数字字符串列表,这是你要的嘛拔出来,那么你应该能够简单地使用

if you know for sure that there are only going to be 2 places where you have a list of digits in your string and that is the only thing you are going to pull out then you should be able to simply use

\d+

这篇关于普通EX pression从字符串中提取号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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