re = /ENERGIA ELETRICA CONSUMO[^%]+%/m
str = 'ENERGIA ELETRICA CONSUMO%
02/2019 347 26/04/2019 305,09 ENERGIA CONS. B.AMARELA kWh 0,54 0,54 29,00% 01/2019 341 11/03/2019 324,39 12/2018 301 26/12/2018 287,83
ENERGIA ELETRICA CONSUMO abc %'
# 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