re = /(\w+\d+\/\d+)\s+(-?\d+\.\d+)(?=.+\1\s+(-\d+\.\d+))/m
str = 'HE-EQM-01#show interfaces transceiver detail | begin Transmit Power
Transmit Power Threshold Threshold Threshold Threshold
Port (dBm) (dBm) (dBm) (dBm) (dBm)
--------- ----------------- ---------- --------- --------- ---------
Te1/2 -3.0 1.6 -1.3 -7.3 -11.3
Te1/3 -17.3 1.6 -1.3 -7.3 -11.3
Te1/4 -40.0 1.6 -1.3 -7.3 -11.3
Te2/2 -3.1 1.6 -1.3 -7.3 -11.3
Te2/3 -40.0 1.6 -1.3 -7.3 -11.3
Te2/4 -40.0 1.6 -1.3 -7.3 -11.3
Optical High Alarm High Warn Low Warn Low Alarm
Receive Power Threshold Threshold Threshold Threshold
Port (dBm) (dBm) (dBm) (dBm) (dBm)
------- ----------------- ---------- --------- --------- ---------
Te1/2 -40.0 1.9 -1.0 -9.9 -13.9
Te1/3 -2.6 1.9 -1.0 -9.9 -13.9
Te1/4 -2.9 1.9 -1.0 -9.9 -13.9
Te2/2 -3.0 1.9 -1.0 -9.9 -13.9
Te2/3 -2.6 1.9 -1.0 -9.9 -13.9'
# 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