简体   繁体   English

正则表达式提取字符串中的第一个和最后一个数字

[英]Regular expression to extract the first and last number in a string

Using these expressions separately, I can extract weight and price from this string, how can I get this to work in a single combined expression? 分别使用这些表达式,我可以从此字符串中提取权重和价格,如何使它在单个组合表达式中起作用?

String: 串:

  0.280    Price $   2.49

Expressions 表达式

(?<weight>\.?\d+(\x2E\d+))
(?<price>\d+\.\d+$)
(?<weight>\.?\d+(?:\x2E\d+)).*?(?<price>\d+\.\d+$)

Try this.See demo. 试试看。看演示。

http://regex101.com/r/zR2tR4/21 http://regex101.com/r/zR2tR4/21

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM