re = /define service\s\{.*(Service 2|Command B).*\}/
str = 'define service {
service_description Service 1
use Template 1
host_name Host 1
check_command Command A
}
define service {
service_description Service 2
use Template 1
host_name Host 1
check_command Command B
}
define service {
service_description Service 3
use Template 1
host_name Host 1
check_command Command C
}'
# Print the match result
str.match(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