re = /^(Sensor #0 -> (?P<EXT>\d+[.]\d+)(?:.*?Sensor #2 -> )(?P<INT>\d+[.]\d+)(?:.*?)(?P<DATE>\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}:\d{2}))/m
str = 'system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 87.81
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:50system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.110
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:51system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.206
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:52system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 87.176
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:53system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.110
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:54system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.110
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:55system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 87.176
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:56system tmp gettemp 0
Sensor #0 -> 69.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 87.81
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:57system tmp gettemp 0
Sensor #0 -> 68.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.15
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:58system tmp gettemp 0
Sensor #0 -> 68.0
OK
dbg_cpu0> system tmp gettemp 2
Sensor #2 -> 88.15
OK
dbg_cpu0>
dbg_cpu0> 2016/11/23 11:04:59system tmp gettemp 0
Sensor #0 -> 68.0
OK
dbg_cpu0> 2016/11/23 11:05:002016/11/23 11:05:012016/11/23'
# 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