试试这个:
String s = "This is the number 2.5. And this is 7";
s = Regex.Replace(s, @"[+-]?\d+(\.\d*)?", m => {return (Double.Parse(m.ToString())*0.8).ToString();});
// s contains "This is the number 2. And this is 5.6"
Run Code Online (Sandbox Code Playgroud)
编辑:在前面添加加号/减号作为可选字符.为避免将3-5中的5作为负数,您可以使用((?<=\s)[+-])?而不是[+-]