David Sopko
David Sopko

Reputation: 5623

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

Upvotes: 2

Views: 317

Answers (1)

vks
vks

Reputation: 67968

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

Try this.See demo.

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

Upvotes: 3

Related Questions