提取字符串中第一个和最后一个数字的正则表达式 [英] 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?
字符串:
0.280 Price $ 2.49
表达式
(?<weight>\.?\d+(\x2E\d+))
(?<price>\d+\.\d+$)
推荐答案
(?<weight>\.?\d+(?:\x2E\d+)).*?(?<price>\d+\.\d+$)
试试这个.看演示.
http://regex101.com/r/zR2tR4/21
这篇关于提取字符串中第一个和最后一个数字的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文