re = /(?m)^line\scon.*(?:\n .+)*/m
str = '!
line con 0
session-timeout 5
exec-timeout 5 0
password 7 1239211A43054F0202D1D
transport output none
line 2
no activation-character
no exec
transport preferred none
transport output pad telnet rlogin lapb-ta mop udptn v120 ssh
stopbits 1
line vty 0 4
session-timeout 5
access-class 125 in
exec-timeout 5 0
length 0
transport input ssh
transport output none'
# 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