re = /^\[(.*?)\s\d{6}\s\d{3}]\[\d]\[ERROR]/m
str = '[02112017 072755 332][1][ERROR]> ----Message : IDC_NO_MEDIA
[02112017 072755 332][1][INFO]> ----
[02112017 104502 724][1][ERROR]> ----Message : DEV_NOT_READY
[02112017 104502 724][1][INFO]> ----
[02112017 104503 331][1][ERROR]> ----Message : DEV_NOT_READY
[02112017 104503 331][1][INFO]> ---- '
# 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