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

自作多情 提交于 2021-02-05 08:45:14

问题


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+$)

回答1:


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

Try this.See demo.

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



来源:https://stackoverflow.com/questions/26021357/regular-expression-to-extract-the-first-and-last-number-in-a-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!