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