re = /(time_(?:namelookup|connect|pretransfer|redirect|starttransfer|total))\s*:\s*([+-]?(?:\d*,)?\d+)/m
str = 'time_namelookup: 0,121668
time_connect: 0,460643
time_pretransfer: 0,460755
time_redirect: 0,000000
time_starttransfer: 0,811697
time_total: 0,811813
-------------
time_namelookup: 0,121665
time_connect: 0,460643
time_pretransfer: 0,460355
time_redirect: 0,000000
time_starttransfer: 0,813697
time_total: 0,811853
-------------
time_namelookup: 0,121558
time_connect: 0,463243
time_pretransfer: 0,460755
time_redirect: 0,000000
time_starttransfer: 0,911697
time_total: 0,811413 '
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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