re = /((|\s|\n)*subnet(|\s|\n)*((\d{1,3}.){3}(\d{1,3}))(|\s|\n)*netmask(|\s|\n)*((\d{1,3}.){3}(\d{1,3}))(|\s|\n)*\{(|\s|\n)+((|\s|\n)+host(|\s|\n)*(\w+)(|\s|\n)*\{(|\s|\n)*(\w*)\:(\w*)\;(|\s|\n)*\}(|\s|\n)*)*\})/
str = '#DHCP Server Configuration file.
deny unknown-clients;
subnet 10.8.140.2 netmask 255.255.255.255 {
host example{
optian:param;
}
host example2{
option2:param2;
}
}
subnet 20.8.110.1 netmask 255.255.255.255 {
host example{
optian:param;
}
}
subnet 20.8.110.1 netmask 255.255.255.255 {
}'
# 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