re = /(?P<time>\d{8}T\d{6}) (?P<rti>.+) (?P<timestamp>\d+)\s?Bus=\s?(?P<bus>.*?)\s?C=\s?0x(?P<cmd>[0-9a-fA-F]{2})\s?S=\s?(?P<status>\w+)\s?RT=\s?(?P<rt>\d+)\s?RDI=\s?0x(?P<rdi>[0-9a-fA-F]{2})\s?EOT=\s?0x(?P<eot>[0-9a-fA-F]{2})\s?Data=\s?(?P<data>([0-9a-fA-F]{2}\s?)*)\s?REPLY=\s?(?P<reply>([0-9a-fA-F]{2}\s?)*)/m
str = '20141011T042032 - 14362918521340 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x06 EOT=0x0c Data=84 9f REPLY=4f c0 c0\\n
20200515T000132 4 2338257812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x1c EOT=0x04 Data= 83 90 88 93 8b 98 88 90 REPLY= 3f
20200515T000132 4 2338257812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x1c EOT=0x04 Data=REPLY= 3f
20200515T000140 12 2343757812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x03 EOT=0x0C Data= 84 9c REPLY= 4c c0 c0
'
# 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