re = /\#\#\#\#\#\#PROJECT\s+Name:\s+(?P<PROJECT_NAME>.+?)\#\#\#\#\#\#
.+?
(?P<OVERLOAD>OVERLOAD\(%\)(?:\s+\d+\.\d+){4}).+?
(?P<LOSS_OF_LOAD>LOSS\s+OF\s+LOAD\s+\(M\)(?:\s+\d+\.\d+){4})/x
str = '######PROJECT Name: ABCD######
foo
bar
baz
OVERLOAD(%) 0.3361 10.0 3.4 2.49 1
LOSS OF LOAD (M) 10.5780 10.0 105.8 14026.67 11
######PROJECT Name: ABCD2######
foo
bar
baz
OVERLOAD(%) 0.3361 10.0 3.4 2.49 1
LOSS OF LOAD (M) 10.5780 10.0 105.8 14026.67 11'
# 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