re = /^.*Download:\s{3,5}\K\d{1,3}\.\d{0,2}(?= Mbps)/m
str = ' Speedtest by Ookla
Server: Fastweb SpA - Milan (id: 7839)
ISP: Wind Tre
Idle Latency: 29.13 ms (jitter: 7.59ms, low: 22.73ms, high: 33.85ms)
Download: 238.14 Mbps (data used: 384.0 MB)
603.92 ms (jitter: 87.34ms, low: 37.24ms, high: 1203.74ms)
Upload: 46.48 Mbps (data used: 43.4 MB)
172.46 ms (jitter: 54.67ms, low: 37.41ms, high: 304.20ms)
Packet Loss: 0.0%
Result URL: https://www.speedtest.net/result/c/f4f1d464-82c6-4980-8b3f-38358ccedbfb
Speedtest by Ookla
Server: Fastweb SpA - Milan (id: 7839)
ISP: Wind Tre
Idle Latency: 23.63 ms (jitter: 0.51ms, low: 23.25ms, high: 25.28ms)
Download: 209.23 Mbps (data used: 356.9 MB)
629.97 ms (jitter: 87.98ms, low: 34.60ms, high: 966.30ms)
Upload: 44.29 Mbps (data used: 39.4 MB)
179.07 ms (jitter: 54.45ms, low: 55.78ms, high: 288.01ms)
Packet Loss: 0.0%
Result URL: https://www.speedtest.net/result/c/ab0ea00c-28c1-4ab0-a65e-3e49ec70160f
Speedtest by Ookla
Server: Fastweb SpA - Milan (id: 7839)
ISP: Wind Tre
Idle Latency: 23.36 ms (jitter: 5.38ms, low: 22.38ms, high: 32.22ms)
Download: 190.75 Mbps (data used: 341.4 MB)
811.89 ms (jitter: 81.96ms, low: 38.70ms, high: 1557.16ms)
Upload: 46.68 Mbps (data used: 78.4 MB)
177.39 ms (jitter: 57.87ms, low: 54.85ms, high: 636.20ms)
Packet Loss: 0.0%
Result URL: https://www.speedtest.net/result/c/6618ad7c-8990-4e8c-9ccf-b2d8726e5757
Speedtest by Ookla
Server: Fastweb SpA - Milan (id: 7839)
ISP: Wind Tre
Idle Latency: 23.37 ms (jitter: 0.97ms, low: 22.43ms, high: 24.39ms)
Download: 7.30 Mbps (data used: 9.5 MB)
788.00 ms (jitter: 148.57ms, low: 195.04ms, high: 2617.58ms)
Download: FAILED
Speedtest by Ookla
Server: Fastweb SpA - Milan (id: 7839)
ISP: Wind Tre
Idle Latency: 24.34 ms (jitter: 5.23ms, low: 23.35ms, high: 32.27ms)
Download: 29.70 Mbps (data used: 36.9 MB)
2842.76 ms (jitter: 102.51ms, low: 36.73ms, high: 3780.32ms)
Upload: 7.91 Mbps (data used: 11.4 MB)
642.92 ms (jitter: 85.25ms, low: 168.67ms, high: 1465.30ms)
Packet Loss: 0.0%
Result URL: https://www.speedtest.net/result/c/c625078c-1efb-4d0c-86f6-47f85ee1838e
Speedtest by Ookla
Server: Fastweb SpA - Milan (id: 7839)
ISP: Wind Tre
Idle Latency: 23.40 ms (jitter: 0.75ms, low: 22.38ms, high: 24.37ms)
Download: 48.79 Mbps (data used: 53.9 MB)
1605.18 ms (jitter: 98.93ms, low: 51.83ms, high: 2609.00ms)
Upload: 10.45 Mbps (data used: 5.4 MB)
350.75 ms (jitter: 80.15ms, low: 60.41ms, high: 742.65ms)
Packet Loss: 0.0%
Result URL: https://www.speedtest.net/result/c/594b8f34-673c-4670-a091-56104e909153
Speedtest by Ookla
Server: Fastweb SpA - Milan (id: 7839)
ISP: Wind Tre
Idle Latency: 24.63 ms (jitter: 4.15ms, low: 24.34ms, high: 32.18ms)
Download: 58.12 Mbps (data used: 69.5 MB)
1889.25 ms (jitter: 101.87ms, low: 96.60ms, high: 3067.85ms)
Upload: 10.45 Mbps (data used: 18.9 MB)
591.63 ms (jitter: 88.04ms, low: 79.24ms, high: 1231.14ms)
Packet Loss: 0.0%
Result URL: https://www.speedtest.net/result/c/35fd9653-3907-4ddd-8680-8ca69b2f0de7
Speedtest by Ookla
Server: Fastweb SpA - Milan (id: 7839)
ISP: Wind Tre
Idle Latency: 22.87 ms (jitter: 1.21ms, low: 22.35ms, high: 23.94ms)
Download: 65.27 Mbps (data used: 76.1 MB)
1603.47 ms (jitter: 97.63ms, low: 48.89ms, high: 2508.82ms)
Upload: 10.92 Mbps (data used: 8.3 MB)
403.47 ms (jitter: 83.73ms, low: 77.31ms, high: 814.42ms)
Packet Loss: 0.0%
Result URL: https://www.speedtest.net/result/c/8de80c8e-cf49-43ee-8964-133e25c7e783
Speedtest by Ookla
Server: Fastweb SpA - Milan (id: 7839)
ISP: Wind Tre
Idle Latency: 24.64 ms (jitter: 1.16ms, low: 22.85ms, high: 25.41ms)
Download: 66.83 Mbps (data used: 77.7 MB)
'
subst = ''
result = str.gsub(re, subst)
# Print the result of the substitution
puts result
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html