-1

例如,我使用什么正则表达式从 .txt 文件中包含的以下文本中提取 1.09487?另外,我将如何修改正则表达式以考虑浮点数为负数的情况(例如,-1.948)?

我在 Google 以及正则表达式生成器上尝试了几个建议,但似乎都没有。似乎我想使用锚点(例如 ^)开始在单词“serial”处搜索数字,然后在“(”处停止,但这似乎不起作用。

.txt 文件中的输出:

熵 = 每个字符 7.980627 位。

Optimum compression would reduce the size
of this 51768 character file by 0 percent.

Chi square distribution for 51768 samples is 1542.26, and randomly
would exceed this value less than 0.01 percent of the times.

Arithmetic mean value of data bytes is 125.93 (127.5 = random).
Monte Carlo value for Pi is 3.169834647 (error 0.90 percent).
Serial correlation coefficient is 1.09487 (totally uncorrelated = 0.0).

谢谢你的帮助。

4

2 回答 2

0

尝试这个:

(-?\d+\.\d+)(?=\s\(totally)

在这里检查

于 2013-07-24T03:00:18.463 回答
0

这应该足够了:

(?<=Serial correlation coefficient is )[-\d.]+

除非你期待垃圾,否则这会很好。

于 2013-07-24T06:41:15.253 回答